The code is as follows:
Table structure
id int phone charpassword char
conn.php
错误原因:'.mysql_error()); //设置字符集,如utf8和gbk等 mysql_query("set names 'utf8'"); //选定数据库 mysql_select_db($db_name,$conn) or die('数据库选定失败!
错误原因:'.mysql_error()); //执行SQL语句(查询) //$result = mysql_query($sql) or die('数据库查询失败!
错误原因:'.mysql_error());?>
login.php
' Unlawful request '); return false; }//Create SQL statement $sql = "SELECT * from lms_users WHERE phone = '". $userName. "' and ' password ' = ' ". $userPassword." '; "; Call the conn.php file for database operation require (' conn.php '); Global $conn; $result =mysql_query ($sql, $conn) or Die (' database query failed! ' ERROR reason: '. mysql_error ()); $flag = 0; while (!! $item =mysql_fetch_assoc ($result)) {$flag + +; }; Only one result can actually be returned. if ($flag >= 1) {$result = Array (echo json_encode ($row); ); echo Json_encode ($result); Exit (); }else {$result = array (' id ' = = 0); echo Json_encode ($result); } return true;? >
Login.html
PHP 测试 登陆
Reply content:
The code is as follows:
Table structure
id int phone charpassword char
conn.php
错误原因:'.mysql_error()); //设置字符集,如utf8和gbk等 mysql_query("set names 'utf8'"); //选定数据库 mysql_select_db($db_name,$conn) or die('数据库选定失败!
错误原因:'.mysql_error()); //执行SQL语句(查询) //$result = mysql_query($sql) or die('数据库查询失败!
错误原因:'.mysql_error());?>
login.php
' Unlawful request '); return false; }//Create SQL statement $sql = "SELECT * from lms_users WHERE phone = '". $userName. "' and ' password ' = ' ". $userPassword." '; "; Call the conn.php file for database operation require (' conn.php '); Global $conn; $result =mysql_query ($sql, $conn) or Die (' database query failed! ' ERROR reason: '. mysql_error ()); $flag = 0; while (!! $item =mysql_fetch_assoc ($result)) {$flag + +; }; Only one result can actually be returned. if ($flag >= 1) {$result = Array (echo json_encode ($row); ); echo Json_encode ($result); Exit (); }else {$result = array (' id ' = = 0); echo Json_encode ($result); } return true;? >
Login.html
PHP 测试 登陆
The development of the words to open the wrong display of PHP (in the php.ini
search configuration display_errors=On
) in order to know what the specific error.
In addition, it is recommended not to use related functions mysql
, with mysqli
related functions or objects instead, the mysql
correlation function is not recommended, and in the latest PHP7 formally removed.
It's a grammatical error,
$result = array( echo json_encode($row););
Here is the wrong one. Can actually open the server on the detailed error output, so you can see the 500 error specific cause of the error