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 ) {
user1691024
  • 199
  • 3
  • 8
  • 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()](http://php.net/mysql_query) manual page. – Álvaro González Apr 28 '13 at 20:55

6 Answers6

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

Maxime
  • 388
  • 3
  • 10
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'");
Fabio
  • 23,183
  • 12
  • 55
  • 64
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' ");
Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289
echo_Me
  • 37,078
  • 5
  • 58
  • 78
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

Antonio E.
  • 4,381
  • 2
  • 25
  • 35
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?

Community
  • 1
  • 1
Memolition
  • 492
  • 1
  • 5
  • 12
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.

al3xst
  • 174
  • 1
  • 13