有谁能告诉我这段代码有什么问题? 基本上我试图使用Android和Php将数据输入到表中。 但我甚至无法让php端工作,因为我收到HTTP错误500,有没有人在这里看到错误? 谢谢!
>
<?php
/* Connect to MySQL and select the database. */
$con = mysql_connect($DB_SERVER,$DB_USERNAME,$DB_PASSWORD);
mysql_select_db ( $DB_DATABASE, $con ) or die ( “Database Selection Failed” );
//$username = $_REQUEST['username'];
//$password = $_REQUEST['password'];
//$givenname = $_REQUEST['givenname'];
//$email = $_REQUEST['email'];
//$phonenumber = $_REQUEST['phonenumber'];
$username = isset($_POST[‘username’]) ? $_POST[‘username’] : ”;
$password = isset($_POST[‘password’]) ? $_POST[‘password’] : ”;
$givenname = isset($_POST[‘givenname’]) ? $_POST[‘givenname’] : ”;
$email = isset($_POST[‘email’]) ? $_POST[‘email’] : ”;
$phonenumber = isset($_POST[‘phonenumber’]) ? $_POST[‘phonenumber’] : ”;
$flag['code']=0;
if ($result = mysql_query ( “INSERT INTO demo VALUES(‘$username’, ‘$password’, `$givenname`, `$email`, ‘$phonenumber’)”, $con )) {
$flag [‘code’] = 1;
echo “hi”;
}
echo (json_encode ( $flag )) ;
mysql_close ( $con );
?>
答案 0 :(得分:0)
是的。修复那些“聪明”的引用:
<?php
/* Connect to MySQL and select the database. */
$con = mysql_connect($DB_SERVER,$DB_USERNAME,$DB_PASSWORD);
mysql_select_db ( $DB_DATABASE, $con ) or die ( "Database Selection Failed" );
//$username = $_REQUEST['username'];
//$password = $_REQUEST['password'];
//$givenname = $_REQUEST['givenname'];
//$email = $_REQUEST['email'];
//$phonenumber = $_REQUEST['phonenumber'];
$username = isset($_POST['username']) ? $_POST['username'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
$givenname = isset($_POST['givenname']) ? $_POST['givenname'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$phonenumber = isset($_POST['phonenumber']) ? $_POST['phonenumber'] : '';
$flag['code']=0;
if ($result = mysql_query ( "INSERT INTO demo VALUES('$username', '$password', `$givenname`, `$email`, '$phonenumber')", $con )) {
$flag ['code'] = 1;
echo "hi";
}
echo (json_encode ( $flag )) ;
mysql_close ( $con );
?>