Hello all!
I currently have a drop down which consists of a list of names generated from the database. My problem is that when selecting a name from the dropdown I would like to insert the name and the corresponding ID into the database table. I am not sure if this is possible with php?
I would appreciate any help.
Here is the code which I made so far.
This populates the dropdown with the names and when processing the form, it inserts the name into the name column. I would just like to add the ID into the ID column which goes along with the chosen name.
<?php
$sql = "SELECT birds.bird_id, birds.name FROM birds";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
?>
<label>Select the bird you have spotted*:</label>
<select name="birdname">
<option value="<?php echo $row['bird_id'] , $row['name']?>"><?php echo $row['name'] ?></option>
<?php
while ($row = mysql_fetch_assoc($result)) { ?>
<option value="<?php echo $row['name'] ?>">
<?php echo (isset($_POST['name']) && $_POST['name'] == $row['bird_id'] ? ' selected="selected"' : '');?>
<?php echo $row['name']?></option>
<?php } ?>