Hello, I need to populate a form with an address using a dropdown list to select the address. The address details is taken from a database.The dropdown list is dynamicaly created from the same database.
I can populate the dropdown list fine, I just need to be able to set the rest of the form. I'm using a MySQL database and PHP4 to interact with it.
This is the code so far.
PHP Code:
<?
mysql_connect("localhost","root");
mysql_select_db("Droppop");
$sql = "SELECT * FROM address";
$result = mysql_query($sql);
while($row=mysql_fetch_array($result)){
$option .= "<option value=".$row[id].">".$row[name]."</option>";
}
?>
HTML Code:
<form>
<select name="name" id="name" onChange="this.refresh">
<option></option>
<?=$option?>
</select><br />
PHP Code:
<?
$sql = "SELECT * FROM address WHERE id = $name";
$result = mysql_query($sql);
while($row=mysql_fetch_array($result)){
$address1 = $row[address_1];
$address2 = $row[address_2];
}
?>
HTML Code:
<input type="text" name="address_1" value="<?=$address1?>" disabled><br />
<input type="text" name="address_2" value="<?=$address2?>" disabled>
</form>
Thanks in advance for your help.
Nalum