代碼如下:
表結構
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
'非法請求')); return false; } //建立SQL語句 $sql="SELECT * FROM lms_users WHERE phone ='".$userName."' AND `password` = '".$userPassword."';"; //調用conn.php檔案進行資料庫操作 require('Conn.php'); global $conn; $result=mysql_query($sql,$conn) or die('資料庫查詢失敗!錯誤原因:'.mysql_error()); $flag=0; while(!!$item=mysql_fetch_assoc($result)){ $flag++; }; //實際只能返回一條結果. 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 測試 登陸
回複內容:
代碼如下:
表結構
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
'非法請求')); return false; } //建立SQL語句 $sql="SELECT * FROM lms_users WHERE phone ='".$userName."' AND `password` = '".$userPassword."';"; //調用conn.php檔案進行資料庫操作 require('Conn.php'); global $conn; $result=mysql_query($sql,$conn) or die('資料庫查詢失敗!錯誤原因:'.mysql_error()); $flag=0; while(!!$item=mysql_fetch_assoc($result)){ $flag++; }; //實際只能返回一條結果. 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 測試 登陸
開發的話要開啟php的錯誤顯示(在php.ini
中搜尋配置display_errors=On
),才能知道具體是啥錯誤。
另外,建議不要使用mysql
相關函數了,用mysqli
相關函數或對象代替,mysql
相關函數早就不推薦使用,並在最新的PHP7中正式移除了。
有語法錯誤吧,
$result = array( echo json_encode($row););
這裡是錯誤的。其實可以開啟伺服器上詳細錯誤的輸出,這樣可以看到500錯誤具體的出錯原因