How to determine an empty query?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kewl_php
Forum Newbie
Posts: 3
Joined: Sat Apr 05, 2003 2:30 am

How to determine an empty query?

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

also add a die() statement within the connection to identify if that's the error. :)
Post Reply