分不多了啊!PHP資料庫查詢,使用者資訊驗證
首先,上代碼
$username=$_POST["name"];
$password=$_POST["password"];
if($username&&$password)
{
if(strpos($username," ")!==false)echo "使用者名稱非法";
else
{
$con=mysql_connect("localhost","root","1");
mysql_select_db("manage",$con);
$sql="
select *
from user
where username='$username' and password='$password'
";
$query = mysql_query($sql) or die(mysql_error());
$row=mysql_num_rows($query);
/*
var_dump($sql);
exit;
*/
if($row==1)echo'登入成功';
else
echo '登入失敗';
}
}
?>
不曉得為什麼,我的$row執行後擷取的值是0,但是呢,我用擷取到的$sql
在資料庫中執行後,明明能查詢到一條記錄,所以能明確,SQL查詢後的函數有問題,但是因為我沒有什麼書籍,還請大家指教。
PHP 資料庫 MySQL
分享到:
------解決方案--------------------
字元編碼對不上,mysql_query(set names utf8) 試試
------解決方案--------------------
資料庫是什麼編碼,查詢前加上:mysql_query("set names utf8"); 試試看。
------解決方案--------------------
像mysql_query("set names utf8"); 這個處理漏掉了,你不要犯這樣的低級錯誤。
------解決方案--------------------
字元編碼對不上,mysql_query(set names utf8)