Need Help guys...
Ive created a form where a user can input First Names and Last Names then sent to database.
Then,
Ive created a dynamic drop down list where the user can select items such as job position or year enrolled. The selected option will be stored to a different table together with the user's first name
and last name.
Although I was able to populate the drop down list from my database. How can I fetch the value
from the drop down list and insert it together with the submitted form to the different table.
Here's my code. Please help... tnx
<html>
<head>
<title>NEW EMPLOYEE</title>
<?php
mysql_connect("localhost","root","");
$db1 = "emp_db1";
$t3 ="emp_table";
mysql_query("create database $db1");
mysql_select_db($db1);
mysql_query("create table $t3(id int not null auto_increment primary key,fname varchar(50),lname varchar(50),mname varchar(50),post_name varchar(50)) engine = InnoDB");
?>
</head>
<BODY bgcolor ="pink">
<?php
if(isset($_POST['submit'])){
$fname =$_POST['fname'];
$lname =$_POST['lname'];
$mname =$_POST['mname'];
$post_name =$_POST['post_name'];
$submit=$_POST['submit'];
error_reporting(E_ALL ^ E_NOTICE);
mysql_query("INSERT INTO emp_table(fname,lname,mname,post_name) VALUES('$fname','$lname','$mname','$post_name')");
}
?>
<form name="add_data" method="post" target="<?php $_SERVER['PHP_SELF']?>">
Register New Employee <br/><br/>
First Name:<input size = "20" type="text" name="fname"/>
Middle Name:<input size = "20" type="text" name="mname"/>
Last Name:<input size = "20" type="text" name="lname"/><br/>
Job Position List:
<select name='post_name'>
<option value="">--- Select ---</option>
<?php
if (isset ($db1)&&$db1!=""){
}
?>
<?php
$list=mysql_query("select * from post_table order by id asc");
//Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\testA\index.php on line 56
while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<?php echo $row_list['id']; ?>"<?php if($row_list['id']==$db1){echo "selected"; } ?>>
<?php echo $row_list['post_name'];?>
</option>
<?php
}
?>
</select>
<input type="submit" name="submit" value="REGISTER" />
</form>
</body>