错误:警告:mysql_num_rows()期望参数1为资源,在第19行的C:\ xampp \ htdocs \ ... \ .... php中给定布尔值 [英] ERROR: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\...\....php on line 19

查看:101
本文介绍了错误:警告: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.

这篇关于错误:警告:mysql_num_rows()期望参数1为资源,在第19行的C:\ xampp \ htdocs \ ... \ .... php中给定布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆