user1691024
user1691024

Reputation: 199

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

$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 ) {

Upvotes: 0

Views: 114

Answers (6)

echo_Me
echo_Me

Reputation: 37233

Try this. You are missing one single quote...

 $result = mysql_query("SELECT * FROM masterip_details WHERE timedate(datetime) = CURDATE() and ip_address='$ip_address' ");

Upvotes: 0

Maxime
Maxime

Reputation: 388

That's probably because the SQL request failed. Try to append or die(mysql_error()) next to your mysql_query, like this :

$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

Upvotes: 1

al3xst
al3xst

Reputation: 184

("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).

Maybe the missing ' will fix your Query.

Upvotes: 0

Memolition
Memolition

Reputation: 494

you are missing a single quote here and ip_address='$ip_address'")

Take a look at this: Why shouldn't I use mysql_* functions in PHP?

Upvotes: 0

Antonio E.
Antonio E.

Reputation: 4391

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

Upvotes: 0

Fabio
Fabio

Reputation: 23480

There is a sintax error in your query, you are missing a quote right after $ip_address just change to

$result = mysql_query("SELECT * FROM  masterip_details WHERE timedate(datetime) = CURDATE() and ip_address='$ip_address'");

Upvotes: 0

Related Questions