Getting frustrated with simple PHP/MySQL problem

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:

include '../db_vars.php';

	$connect = mysql_connect($dbhost, $dbuser, $dbpasswd) or die (mysql_error());
	mysql_select_db($dbname);

echo $_GET['lodgeindex'];

if (isset($_GET['choice'])){

$choice=$_GET['choice'];

$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";

$result=mysql_query($recent_sql);
  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.

 type='$choice'ORDER

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

Change this

$result=mysql_query($recent_sql);

to

$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.