0

I Have a problem with syntax error on the following code

$myregion = $_POST['region'];echo $myregion;$names = mysql_query("SELECT * FROM course_name WHERE Region=$myregion"); while($row = mysql_fetch_array($names)) {echo $row['Name_of_Course'], " " , $row['Region'], " " , $row['Price'],"<br>";}$myregion = $_POST['region'];
echo $myregion;
$names = mysql_query("SELECT * FROM course_name WHERE Region=$myregion");

while($row = mysql_fetch_array($names)) {
echo $row['Name_of_Course'], " " , $row['Region'], " " , $row['Price'],"<br>";
}

error is fetch_array expectects parameter 1 to be resource, boolean given on line 47

This code worked fine if I hard coded the Where condition but once I have put the $variable in, i get the error?

Could nyone help as I am new to php mysql

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by cyd44
0
... Region='$myregion'")

BUT

You're using unsanitized input data - clean it with something like mysql_real_escape_string.

Edited by diafol: n/a

0
... Region='$myregion'")

BUT

You're using unsanitized input data - clean it with something like mysql_real_escape_string.

Many thanks Ardav, that cured it. Sorry if I appear thick, I am very new to php and dont know the synatx properly yet.

Cheers mate

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.