Hi there. I'm having a problem getting values from a drop down to insert into a table. What I want to do is get the key for the value and then insert that. For example: I have a table called format which holds an auto incremented ID key and a format type, the format types are populated to a drop down and the user can pick one. But what I need in the INSERT isn't the format type but its ID and for some reason all I'm getting is zero's. The format table is prepopulated, meaning I've gone in and put values in it myself without the use of php or anything since I don't plan on a user being able to edit this table. Here's some code.
<tr>
<td>Format:</td>
<td>
<?php
if(mysql_num_rows($format)){
$select= '<select name="format">';
while($rs=mysql_fetch_array($format)){
$select.='<option value="'.$rs['formatID'].'">'.$rs['formatType'].'</option>';
}
}
$select.='</select>';
echo $select;
?> </td>
</tr>
Sorry for the state of it, notepad++ tabbing doesn't seem to copy and paste well
$format=$_POST['format'];
$formatID = mysql_query("select formatID from format where formatType = '$format'") or die(mysql_error());
but the select statement doesn't seem to be returning the value properly or something. In order to get this to work with a few non-drop down fields I had to do it this way:
mysql_query("insert into authors(authorName, authorBio) values('$author', '$bio')") or die(mysql_error());
//$authorID = mysql_query("select authorID from authors where authorName = '$author' and authorBio = '$bio'") or die(mysql_error());
$authorID = mysql_insert_id();
which gives me the proper value right now, though I'm thinking this might cause me some errors when I try to avoid duplicating entries.