错误:警告:mysql_num_rows()期望参数1为资源,在第19行的C:\ xampp

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

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


慕妹3242003
浏览 478回答 3
3回答

元芳怎么了

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

倚天杖

我真的不知道,我还要说些什么。该表kossu.nonexistenttable不存在。我认为,这确实很明显,这意味着什么。在您的情况下,似乎没有members要查询的表。另外我mysql_error()没有说mysql_errno()。对于第一个,您将收到具体的错误消息,而不是不确定的错误代码。这比您从PHP手册中获得的示例输出要有用一些;)
打开App,查看更多内容
随时随地看视频慕课网APP