[resolved] What is wrong with this syntax?
PHP Code:
$sql = mysql_query('SELECT golf_course_code FROM availability WHERE golf_course_code='.$_POST['txtGolfCourse'].' AND t_date="'.$temp_date.'"');
while ($row = mysql_fetch_object($sql)) {\
echo $row->golf_course_code.'<br>';
}
I'm getting this rather unhelpful error message:
Quote:
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in C:\golf_engine_php\xt_index.php on line 33
Any help is appreciated.
Many thanks.
Re: What is wrong with this syntax?
You have to execute your query before you can get the rows it returns. The mysql_query() function does this and returns a result point which can then be supplied as an argument to functions like mysql_fetch_object().
PHP Code:
$sql = mysql_query('SELECT golf_course_code FROM availability WHERE
golf_course_code='.$_POST['txtGolfCourse'].' AND t_date="'.$temp_date.'"');
if (! $result = mysql_query($sql)) {
die(mysql_error());
}
while ($row = mysql_fetch_object($result)) {
echo $row->golf_course_code.'<br>';
}