【发布时间】:2011-08-28 01:52:15
【问题描述】:
我不断收到使用mysql_num_rows() 的错误消息,你能帮我找出我的代码出了什么问题吗?
这是我的代码:
<?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
当我搜索该错误时,它会说
1146: Table 'kossu.nonexistenttable' doesn't exist
但我不知道这是什么意思...请帮忙。
【问题讨论】:
-
$sql可能是错误的,这就是它失败的原因。检查查询是否正确。 -
您的 sql 语法可能有错误,mysql_query 返回 false。打印出整个查询并将其粘贴到 phymyadmin(或类似的)中,看看它是否正确执行。
-
@AllisonC 我在 mysql 尝试了 sql 语法,它成功返回了 id。
-
阅读下面的任意答案,然后使用
mysql_error()找出您的查询到底发生了什么。无需猜测。
标签: php