littletechie Posted May 11, 2009 Share Posted May 11, 2009 Hey guys, I'm pretty new to PHP, so bear with me I have created a registration form for a training session for my job. All of the regular text box fields submit to the mysql db just fine, it's the drop down menu values that it doesn't read. It doesn't present and errors or anything, so I am obviously just missing some key element so that the value is recognized and inserted. here is my html code for the selection box.. Your role: <select><option value = "Select">Select...</option> <option value = "Attorney">Attorney</option> <option value = "Paralegal">Paralegal</option> <option value = "Secretary">Secretary</option> <option value = "IT Staff">IT Staff</option> <option value = "Financial Staff">Financial Staff</option> </select> and my php code.. <?php $fname = $_POST['FirstName']; $lname = $_POST['LastName']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $phone = $_POST['phone']; $email = $_POST['email']; $role = $_POST['role']; #ensure value exists #if($FirstName and $LastName and $address and $city and $state and $zip and $phone and $email and $role){ #connect to mysql $conn = @mysql_connect("localhost", "root", "password") or die("Err:Conn"); #select db $rs = @mysql_select_db("test", $conn) or die("Err:Db"); #create query $sql = "INSERT INTO training (FirstName, LastName, address, city, state, zip, phone, email, role) VALUES(\"$fname\", \"$lname\", \"$address\", \"$city\", \"$state\", \"$zip\", \"$phone\", \"$email\", \"$role\")"; #execute query $rs = mysql_query($sql, $conn); #confirm the added record details if($rs){ echo( "<b>$fname $lname</b> has been added to the database for training." ); echo ( "<br><br><form><input type = 'submit' value = 'Home' onClick = ' '></form>" ); } else if(!$rs){echo("No record added.");} #} ?> any insight would be greatly appreciated! Thanks. Link to comment https://forums.phpfreaks.com/topic/157690-insert-into-db-from-drop-down-box/ Share on other sites More sharing options...
Ken2k7 Posted May 11, 2009 Share Posted May 11, 2009 Please use tags. Your select dropdown doesn't have a name attribute so you can't really get the value. Link to comment https://forums.phpfreaks.com/topic/157690-insert-into-db-from-drop-down-box/#findComment-831590 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.