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

Member Avatar for diafol
... Region='$myregion'")

BUT

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.