Jump to content

Select From Where Help


Pauls74462

Recommended Posts

I have this code on my page. it will not work. I can replace the " . $_POST['Schools'] " with the schoolid and it will work.

$sql  = "SELECT lname FROM teachers WHERE schoolid = . $_POST['Schools'] . ";

The " . $_POST['Schools'] " comes from a drop down menu. I do get the echo [The school is "Keota" with the ID: "31SIS043"]with this line:

echo 'The school is "' . $row['school'] . '" with the ID: "' . $_POST['Schools'] . '"'; 

which is correct, but will not list the teachers from that school.Paul

Link to comment
Share on other sites

The ID appears to be a string, so you need to have quotation marks around the posted value (you also forgot closing quotation marks before the concatenation). Don't forget to sanitize the string first, however.

$id = mysql_real_escape_string($_POST['Schools']);$sql = "SELECT lname FROM teachers WHERE schoolid = '$id'";

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...