Hello! I really need help! I have these codes but I can't make them work.
In my first drop down list box, if I chose one option, I only wanted to see its appropriate value in the second drop down list box. For example, if I chose 'Quezon City' in the first drop down list box, I only wanted to see the areas in like, 'Ayala', 'Loyola', so on and so forth. But instead, my codes shows all the places even though I have already chosen one option! Please help! Thank you in advance!
Btw, the values in my drop down list boxes are in my database.
Select City:
<form method="post" action="process.php">
<label for="select"><select id="city" name="city" value="Select" size="1">
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="gilmorewines"; // Database name
$tbl2="deldetails"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = "SELECT * FROM delcity";
$result = mysql_query($sql) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
$id=$row["city_id"];
$hello = $_POST['city_id'];
$cname=$row["cityname"];
$options.="<OPTION VALUE=\"$id\">".$cname;
}
?>
<option>
<? echo $options; ?>
</option>
</label></select><br>
Select Area:<br>
<label for="select"><select name="area" value="Select" size="1"><br>
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="gilmorewines"; // Database name
$tbl2="deldetails"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
if ($cname.value == "Quezon City"){
$sql = "SELECT * FROM deldetails WHERE city LIKE 'q%'";
}
if ($cname.value == "San Juan City"){
$sql = "SELECT * FROM deldetails WHERE city LIKE 's%'";
}
if ($cname.value == "Pasig City"){
$sql = "SELECT * FROM deldetails WHERE city LIKE 'p%'";
}
if ($cname.value == "Taguig City"){
$sql = "SELECT * FROM deldetails WHERE city LIKE 't%'";
}
else{
$sql = "SELECT * FROM deldetails";
}
$result = mysql_query($sql) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
$id2=$row["area_id"];
$aname=$row["area"];
$options2.="<OPTION VALUE=\"$id2\">".$aname;
}
?>
<option>
<? echo $options2 ?>
</option>
</label> </select>
<input type="submit" name="Submit" value="Submit">
</form>