Hi
I have what is probably a simple question as still fairly new to php.
I have a webpage which has two drop down lists, both dynamically created from sql databases.
I need the user to be able to select a client in the first drop down list and it to then populate the second list with contacts for that client.
At present I can get the form to post back to itself but the first list keeps reverting to the last option in the list.
Here is the code for to create the 1st drop down as well as the code to capture the selected option.
<form name="choose client" action="new_job_form.php" method="post">
<select name="select_client" onchange="this.form.submit()" ;>
<?php
$query1 = "SELECT * FROM clients ORDER BY clientName";
$result = mysql_query($query1);
if (!$result) {
die(mysql_error());
}
while ($row = mysql_fetch_assoc($result)) {
echo '<option value = "' . $row['ClientId'] . '" selected="'.$row['ClientName'].'" name="' . $row['ClientName']. '" >' . $row['ClientName']. '</option>';
}
?>
</select>
</form>
This populates the list as I need it to but isn't catching the data correctly.This is the code for the 2nd drop down.
<select name="contact">
<?php
$query2= "SELECT * FROM client_contact, clients WHERE client_contact.ClientID=clients.clientID";
$result2 = mysql_query($query2);
if (!$result2) {
die (mysql_error());
}
?>
</select>
Apologies if the code is not the tidiest in the world - I am still learning :)
Many thanks in advance for your help.