> Hi all:
>
> I am trying to create a registration form whereby one of the user input is as
> follows: (a drop down menu with values retrieved from DB):
> -----------------------------------------------------------------------------
>
> <td class="lighter" width="350">Class Code:</td>
> <td class="lighter" width="450">
> <select class="textarea" name="class_code">
> <?
> $sql = mysql_query("SELECT DISTINCT class_code FROM class");
> while ($row = mysql_fetch_array($sql))
> {
> print "<OPTION VALUE=\"$class_code\" >" .$row["class_code"]. "</option>";
> }
> $result = $db->query($sql);
>
> ?>
>
> </select>
1. The variable $class_code is undefined. Use:
print "<OPTION VALUE=\"". $row[ "class_code" ] ."\" >"
.$row["class_code"]. "</option>";
2. Use mysql_fetch_assoc() instead mysql_fetch_array() if you want to
fetch hashed array ONLY.
3. After the form submitted the variable $_REQUEST[ 'class_code' ]
contains selected item value, for example "1234". You can insert it into
database using the following SQL query:
$sql = 'INSERT INTO `class` (`class_code`, `another_field`, `third_etc`
) VALUES( ' . mysql_escape_string( $_REQUEST[ 'class_code' ] ) . ',
"value", "value_etc" )';
Sorry for my english.
Pavel.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php