Not sure if this is a php or mysql config issue...

A

Anonymous

Guest
On my test server I was able to run a mysql query that involves an empty variable:

Code:
	$result = mysql_query("SELECT * FROM classifieds WHERE adnumber = $adnumber LIMIT 1", $link_id);
	$query_data2 = mysql_fetch_object($result);

Where $adnumber is null (not just 0). Anyways, my test server ran these fine and just returned empty. On my main server though it returns this error:

Code:
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/atomicde/public_html/profile.php on line 25

I guess I could recode to define the variables if they happen to be empty, but I am pretty used to (and my massive script has been tested around) the test server being able to "WHERE columnname = "

Is there a way to reconfig mysql/php to do this?
 
It seems that the problem is that the query isn't returning any records, in which case you can't read its rows (since there are none) without getting an error.

The best practice is to check whether any rows were returned before trying to read them.
 
Code:
	$result = mysql_query("SELECT * FROM classifieds WHERE adnumber = $adnumber LIMIT 1", $link_id);
	@$query_data2 = mysql_fetch_object($result);
if (!$query_data2) {echo "sorry....";}
 
Back
Top