[英]MYSQL num rows error
Hi I am trying to use a piece of code which I have used before to quickly test out an idea, however I Keep getting the following error. 嗨,我正在尝试使用一段我之前使用过的代码来快速测试一个想法,但是我仍然遇到以下错误。
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in 警告:mysql_num_rows()期望参数1为资源,布尔值在
$result = mysql_query("SELECT * FROM masterip_details WHERE timedate(datetime) = CURDATE() and ip_address='$ip_address");
$num_rows = mysql_num_rows($result);
if( $num_rows > 0 ) {
That's probably because the SQL request failed. 这可能是因为SQL请求失败。 Try to append
or die(mysql_error())
next to your mysql_query, like this : 尝试在您的mysql_query旁边附加
or die(mysql_error())
,如下所示:
$result = mysql_query("SELECT * FROM masterip_details WHERE timedate(datetime) = CURDATE() and ip_address='$ip_address") or die(mysql_error());
This should output the error so that you can fix it. 这应该输出错误,以便您可以修复它。
EDIT: And I can also give you a clue of what that error could be. 编辑:我也可以给你一个线索,该错误可能是。 At the end of your request, you're not closing the single quote after
$ip_address
在请求结束时,您不会关闭
$ip_address
之后的单引号
您的查询中存在一个sintax错误,您只需在$ip_address
更改为后就缺少引号
$result = mysql_query("SELECT * FROM masterip_details WHERE timedate(datetime) = CURDATE() and ip_address='$ip_address'");
Try this. 尝试这个。 You are missing one single quote...
您缺少一个单引号...
$result = mysql_query("SELECT * FROM masterip_details WHERE timedate(datetime) = CURDATE() and ip_address='$ip_address' ");
You keep getting that error because your query is wrong: 由于查询错误,您不断收到该错误:
mysql_query("SELECT * FROM masterip_details WHERE timedate(datetime) = CURDATE() and ip_address='$ip_address"
is missing a quote after $ip_address
$ip_address
后缺少报价
you are missing a single quote here and ip_address='$ip_address'")
您在此处缺少单引号,
and ip_address='$ip_address'")
Take a look at this: Why shouldn't I use mysql_* functions in PHP? 看一下: 为什么我不应该在PHP中使用mysql_ *函数?
("SELECT * FROM masterip_details WHERE timedate(datetime) = CURDATE() AND ip_address='$ip_address'")
You missed an ' at the end of your SQL-Statement and you should write "AND" uppercased, since all other SQL-Keywords are written uppercased (not essential, but easier to read). 您在SQL语句的末尾错过了一个',并且应该将大写的“ AND”写成大写,因为所有其他SQL关键字都是大写的(不是必需的,但更易于阅读)。
Maybe the missing ' will fix your Query. 也许缺少的'将解决您的查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.