错误:警告:mysql_num_rows()期望参数1为资源,在第19行的C:\ xampp \ htdocs \ ... \ .... php中给定布尔值
问题描述:
我不断使用mysql_num_rows()
收到错误消息,您能帮我弄清楚我的代码出了什么问题吗?
I keep on receiving an error message using mysql_num_rows()
, can you help me figure out what went wrong on my code?
这是我的代码:
<?php
//check if the user press submit
if (isset($_POST['submit'] )) {
$customer = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["username"]); // filter everything but numbers and letters
$password = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password"]); // filter everything but numbers and letters
$sql = mysql_query("SELECT id FROM members WHERE username='$customer' AND password='$password' LIMIT 1"); // query the person
// ------- MAKE SURE PERSON EXISTS IN DATABASE ---------
$existCount = mysql_num_rows($sql); // count the row nums
if ($existCount == 1) { // evaluate the count
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
}
$_SESSION["id"] = $id;
$_SESSION["customer"] = $customer;
$_SESSION["password"] = $password;
header("location: index.php");
exit();
} else {
echo 'That information is incorrect, try again <a href="customer_login.php">Click Here</a>';
exit();
}
}
?>
我已经按照您的建议尝试了mysql_errno()
.它回显1146
I've tried mysql_errno()
as you advised.. and it echo 1146
当我搜索该错误时会说
1146: Table 'kossu.nonexistenttable' doesn't exist
但是我不知道这意味着什么...请帮忙.
But I don't know what it means... Please help.
答
可能mysql_query()
失败.在这种情况下,它返回false
.使用 mysql_error()来了解发生了什么.
Probably mysql_query()
failed. In this case it returns false
. Use mysql_error() to find out, what happens.