0

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 ) {
1
  • 1
    I never get heard when I say this but... You cannot assume that all queries succeed and start guessing otherwise. You need to do proper error checking. There's an example right in mysql_query() manual page. Commented Apr 28, 2013 at 20:55

6 Answers 6

1

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

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Uppercasing AND isn't strictly necessary.
0

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'");

Comments

0

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

Comments

0

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?

Comments

0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.