Re: INSERT dynamic values problem - Need help urgently!

From: Date: Fri, 27 Feb 2004 16:39:14 +0000
Subject: Re: INSERT dynamic values problem - Need help urgently!
Groups: php.db 
Request: Send a blank email to php-db+get-33199@lists.php.net to get a copy of this message
> 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.

« previous php.db (#33199) next »