-2
這是我的代碼:Mysql的NUM行總是要1
<?php
$host="localhost";
$user="root";
$pass="";
$db="comportal";
mysql_connect($host, $user,$pass);
mysql_select_db($db);
if(isset($_POST['username'])){
$username=$_POST['username'];
$password=$_POST['password'];
$sql="SELECT * FROM user WHERE username='".$username."' AND password='".$password."' LIMIT 1";
$res= mysql_query($sql);
if(mysql_num_rows($res)==1){
echo "Successfully logged in.";
exit();
}
else{
echo "Invalid Information. Please return to the previous page.";
exit();
}
}
?>
,我總是得到這樣的錯誤:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\sample\login.php on line 20
Invalid Information. Please return to the previous page.
然後我試圖改變
if(mysql_num_rows($res)==1){
echo "Successfully logged in.";
exit();
與
if($res==true){
echo "Successfully logged in.";
exit();
但是,現在它在邏輯上是錯誤的。它說成功登錄,即使它沒有存儲在數據庫中。
請問我該如何解決?
可能重複的[mysql \ _fetch \ _array()期望參數1是資源(或mysqli \ _result),布爾給定](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects -parameter -1-待資源或-mysqli的對結果布爾) – 2015-02-17 23:12:57