The select tag with php/mysql

I want to select from my table driving_licence_school, with the select tag, every school that is in the selected town, but I guess that the second query is not good, or something else.

Please someone help me to see where I’m wrong.

<form class="driving_licence_school" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
$query_record = "SELECT * FROM driving_licence_school ORDER BY id ASC  ";
$record = mysql_query($query_record) or die(mysql_error());
$row_record = mysql_fetch_assoc($record);
$totalRows_record = mysql_num_rows($record);
$town = $row_record['town']; 
<select name="town" id="town"> 
<option  value="0">- - Town - -</option>
<?php do { ?>
<option value="<?php echo $row_record['town']; ?>"><?php echo $row_record['town']; ?></option>
<?php } while ($row_record = mysql_fetch_assoc($record)); ?>
 <input type="Submit" name="search" value="search" class="button" />

$sql = "SELECT *   FROM driving_licence_school WHERE ";
$result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR);

while ($list = mysql_fetch_assoc($result)) {
echo '<ul>'.
'<li><span class="text_h2">'.$list['school_name'] .'</li>'.
'<li><span class="text_h3">Oras:</span> '.$list['town'] .'</li>'.
'<li><span class="text_h3">Telefon:</span> '.$list['phone'] .'</li>'.
'<li><span class="text_h3">Adresa:</span> '.$list['address'] .'</li>'.
'<li><span class="text_h3">Email:</span> '.$list['email'] .'</li>'.
'<li><span class="text_h3">Descriere:</span> '.$list['about'] .'</li>'.

$sql = "SELECT *   FROM driving_licence_school WHERE ";

You didn’t finish writing the query: WHERE what?

$sql = "SELECT * FROM driving_license_school WHERE town = '" . mysql_real_escape_string($_POST['town']) . "'";

As a side note I’d suggest to make trigger_error(); way more informative with placing there mysql_error() output along with $sql variable content for debugging purposes.

mysql_query($sql) or trigger_error(mysql_error()." in ".$sql, E_USER_ERROR);

Thank you very much Dan. Works :slight_smile:

you have to change in second part of code you have to provide where clouse
i am sending with that



$town = $_POST[‘town’];

$sql = “SELECT * FROM driving_licence_school WHERE town=‘$town’”;

$result = mysql_query($sql) or trigger_error(“SQL”, E_USER_ERROR);

while ($list = mysql_fetch_assoc($result)) {

echo ‘<ul>’.

‘<li><span class=“text_h2”>’.$list[‘school_name’] .‘</li>’.

‘<li><span class=“text_h3”>Oras</span> ‘.$list[‘town’] .’</li>’.

‘<li><span class=“text_h3”>Telefon</span> ‘.$list[‘phone’] .’</li>’.

‘<li><span class=“text_h3”>Adresa</span> ‘.$list[‘address’] .’</li>’.

‘<li><span class=“text_h3”>Email</span> ‘.$list[‘email’] .’</li>’.

‘<li><span class=“text_h3”>Descriere</span> ‘.$list[‘about’] .’</li>’.





try this i hope it will work…