For some reason a simple database connection script that was working fine is now throwing up the following error message:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/bounce6/public_html/inf.php on line 45
The code is as follows:
$connect = mysql_connect($dbhost, $dbuser, $dbpasswd) or die (mysql_error());
$recent_sql = "SELECT id, title, type, price, description, hire, age, adults, requirements, overnight, picture, dim, gallerypics FROM range WHERE type='$choice'ORDER BY price ASC";
while ($recent = mysql_fetch_array($result))
[I].... print out results[/I]
Line 45 is the beginning of the while statement.
Can someone tell me if there's any problem with that PHP code, or if there's any other reason why these errors may now have suddenly started cropping up.
From an SQL point of view, I've checked that the name of the table is correct and that all of the table fields are valid ... and it's still not working. Is there something else I should be checking??
Thanks very much for your help ...
Your SQL query is invalid, which is why there's no result resource to fetch rows from.
You lost your space between that field and the ORDER BY clause.
it's gotta be something else, dan -- mysql is smart enough to parse the sql without that particular space being there
$result=mysql_query($recent_sql) or die(mysql_error());
If the query fails, which it is, you'll see an error message describing the problem. You also need to look into sql injection, because you are opening up security holes in your current code. Depending what those variables are, they could even be the cause of your problem.