小编典典

错误:警告:mysql_num_rows()期望参数1为资源,在第19行的C:\ xampp \ htdocs \…\…php中给定布尔值

php

我不断收到使用的错误消息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

但是我不知道这意味着什么…请帮助。


阅读 215

收藏
2020-05-26

共1个答案

小编典典

可能mysql_query()失败了。在这种情况下,它返回false。使用mysql_error()找出会发生什么。

2020-05-26