I'm definitely not an expert, and I cannot figure out why this is happening. When I run a particular script I get the following error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/dev1/public_html/scheduler_forced.php on line 47
Normally, I would check the mysql_error(), find where I had messed up, and fix the problem. But in this case the query proceeds from the point of error, and works perfectly, and mysql_error returns a blank.
$db = mysql_connect($mysql_host,$mysql_user,$mysql_password);
$sql = "INSERT INTO cronlog (runtime, ip, daily, weekly, comment) VALUES ('$runtime', '$ip', '', '', 'Forced scheduler')";
$result = mysql_query($sql,$db);
// loop through the towns and prepare summary
$sql = "SELECT townID, dailySummaryTime, weeklySummaryDay, weeklySummaryTime FROM towns";
$result = mysql_query($sql, $db);
while ($row = mysql_fetch_array($result))
$townNumber = $row['townID'];
$dailySummaryTime = $row['dailySummaryTime'];
$weeklySummaryDay = $row['weeklySummaryDay'];
$weeklySummaryTime = $row['weeklySummaryTime'];
... and the code continues on from here...
The error occurs in the 'while' command in line 11 above (that's line 47 in my actual script).
I cannot figure out why I am getting an error. The connection to the database is identical code that I use literally hundreds of times on this site. The query on lines 4 and 5 works properly. The query on lines 8, 9 and 11 works fine also. mysql_num_rows returns 1 (which is correct), and the variables $townNumber, $dailySummaryTime, etc. all retrieve the proper values from $row. When I look at $result is shows "Resource ID #14", which I think is correct.
If it were not for the error message that pops up on the page when I run the script, I would have no idea anything was wrong, as the script does what it is supposed to do and finishes all of its necessary steps.
I must be missing something incredibly obvious, but I cannot tell what it is. Anyone have any ideas?
Thanks in advance for your help...