skypanther
Exalted Code Master!
I've been staring at this for hours and I just don't see the error. Can you spot it?
The if(!$results) is not being executed and the echo statement outputs Resource id #2. If I echo out $numresults, I get "1" as my data should give me. So it seems that $results is really a valid result resource. But, the while ($row = mysql_fetch_array($results, MYSQL_ASSOC)) statement fails with an mysql_fetch_array(): supplied argument is not a valid MySQL result resource error.
The query actually works when I run it in MySQL-Front. But it seems to be the failure here. If I remove the AND (listid = 1 OR listid = 7) portion of the query, the code works.
What gives?
Tim
PHP:
$link = @mysql_connect('myserver','user','password');
mysql_select_db('db');
$query = "SELECT listid, unique_id FROM smpro_list WHERE address = '".$email."' AND (listid = 1 OR listid = 7)";
if($link !== FALSE) $results = mysql_query($query, $link);
else die('connection failed');
if (!$results) {
die('Invalid query: ' . mysql_error());
}
$numresults = mysql_num_rows($results);
echo $results;
if($numresults == 1) {
while ($row = mysql_fetch_array($results, MYSQL_ASSOC)) {
...
The if(!$results) is not being executed and the echo statement outputs Resource id #2. If I echo out $numresults, I get "1" as my data should give me. So it seems that $results is really a valid result resource. But, the while ($row = mysql_fetch_array($results, MYSQL_ASSOC)) statement fails with an mysql_fetch_array(): supplied argument is not a valid MySQL result resource error.
The query actually works when I run it in MySQL-Front. But it seems to be the failure here. If I remove the AND (listid = 1 OR listid = 7) portion of the query, the code works.
What gives?
Tim