Page 1 of 1

How to determine an empty query?

Posted: Sat Apr 05, 2003 2:30 am
by kewl_php
can anybody help me please? i tried to use mysql_fetch_array but it returned this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

I would like to know how i could determine whether the result of my query is empty or not. It's like determining if a certain username and password exists in the database or not. Thanks a lot people.

Posted: Sat Apr 05, 2003 3:28 am
by twigletmac
You need to add some error handling to your mysql_query() call because it appears as if your query might be failing. Don't have your code so I can only offer an example:

Code: Select all

$sql = "SELECT field1, field2 FROM table WHERE field1='$somevariable' AND field2='$someothervariable'";
@$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
Using mysql_error() should give you a more useful, MySQL generated error which should help you find out what is wrong with the SQL statement.

Mac

Posted: Sat Apr 05, 2003 5:52 am
by m3mn0n
also add a die() statement within the connection to identify if that's the error. :)