Jump to content

insert into db from drop down box


littletechie

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.