Hi,
Please help me find out what wrong with my codes in inputting from my form to mysql database using drop down menu. Below is the codes I used. Only the drop down is not working but the "input text" are successfully adding data to mysql. I just try first using the month as drop down. The month data type I used in mysql database is varchar. Im new in PHP please help me. Thanks
[code=php]
<?php /* Created on: 10/12/2006 */ ?>
<html>
<body>
<?php
include ('./header.php');
include ('./menu1.php');
if (isset($_POST['submit'])) { //handle the form
if ($dbc = mysql_connect ('localhost', 'root', 'jan03001')) {
if (!@mysql_select _db ('hris')) {
die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>');
}
} else {
die ('<p>Could not could not connect to Mysql because: <b>' . mysql_error() . '</b></p>');
}
//define the query
$query = "INSERT INTO personlinfotbl2 (empid, firstname, lastname, bmonth) VALUES ('{$_POST[empid]}', '{$_POST['firstname']}', '{$_POST['lastname']}', '{$_POST['bmonth']}')";
//execute the query
if (mysql_query ($query)) {
print '<p> <center><font face="arial" color="red" size="3">The Personal Information entry has been added. Continue to add data. </font></center></p>';
} else {
print '<p> <center><font face="arial" color="red" size="3">Could not add the entry because: <b>" . mysql_error() . "<b>. The query was $query.</font></center></p>';
}
mysql_close();
}
//display the form
?>
<form action="add_per sonalinfo2.php" method="post">
<center>
<table width=44% align="center">
<tr>
<td colspan=3><b>Fi ll-up this form to add Personal Information</b></td>
</tr>
<tr>
<td>Employee Number: </td><td><input type="text" name="empid" size="28" maxsize="100" /></td>
</tr>
<tr>
<td>First Name: </td><td><input type="text" name="firstname " size="28" maxsize="100" /></td>
</tr>
<tr>
<td>Last Name: </td><td><input type="text" name="lastname" size="28" maxsize="100" /></td>
</tr>
<tr>
<td>Birth Date: </td>
<td>
<select name="month">
<option value="January" >January</option>
<option value="February ">February</option>
<option value="March">M arch</option>
<option value="April">A pril</option>
<option value="May">May </option>
<option value="June">Ju ne</option>
<option value="July">Ju ly</option>
<option value="August"> August</option>
<option value="Septembe r">September </option>
<option value="October" >October</option>
<option value="November ">November</option>
<option value="December ">December</option>
</select></td>
</tr>
<tr>
<td colspan=2><inpu t type="submit" name="submit" value="Add to Personal Info Table" />
<input type='reset' name='reset' value='Reset'></td>
</tr>
</table>
</center>
</form>
<?php
include ('./footer.php');
?>
</body>
</html>
[/code]
Please help me find out what wrong with my codes in inputting from my form to mysql database using drop down menu. Below is the codes I used. Only the drop down is not working but the "input text" are successfully adding data to mysql. I just try first using the month as drop down. The month data type I used in mysql database is varchar. Im new in PHP please help me. Thanks
[code=php]
<?php /* Created on: 10/12/2006 */ ?>
<html>
<body>
<?php
include ('./header.php');
include ('./menu1.php');
if (isset($_POST['submit'])) { //handle the form
if ($dbc = mysql_connect ('localhost', 'root', 'jan03001')) {
if (!@mysql_select _db ('hris')) {
die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>');
}
} else {
die ('<p>Could not could not connect to Mysql because: <b>' . mysql_error() . '</b></p>');
}
//define the query
$query = "INSERT INTO personlinfotbl2 (empid, firstname, lastname, bmonth) VALUES ('{$_POST[empid]}', '{$_POST['firstname']}', '{$_POST['lastname']}', '{$_POST['bmonth']}')";
//execute the query
if (mysql_query ($query)) {
print '<p> <center><font face="arial" color="red" size="3">The Personal Information entry has been added. Continue to add data. </font></center></p>';
} else {
print '<p> <center><font face="arial" color="red" size="3">Could not add the entry because: <b>" . mysql_error() . "<b>. The query was $query.</font></center></p>';
}
mysql_close();
}
//display the form
?>
<form action="add_per sonalinfo2.php" method="post">
<center>
<table width=44% align="center">
<tr>
<td colspan=3><b>Fi ll-up this form to add Personal Information</b></td>
</tr>
<tr>
<td>Employee Number: </td><td><input type="text" name="empid" size="28" maxsize="100" /></td>
</tr>
<tr>
<td>First Name: </td><td><input type="text" name="firstname " size="28" maxsize="100" /></td>
</tr>
<tr>
<td>Last Name: </td><td><input type="text" name="lastname" size="28" maxsize="100" /></td>
</tr>
<tr>
<td>Birth Date: </td>
<td>
<select name="month">
<option value="January" >January</option>
<option value="February ">February</option>
<option value="March">M arch</option>
<option value="April">A pril</option>
<option value="May">May </option>
<option value="June">Ju ne</option>
<option value="July">Ju ly</option>
<option value="August"> August</option>
<option value="Septembe r">September </option>
<option value="October" >October</option>
<option value="November ">November</option>
<option value="December ">December</option>
</select></td>
</tr>
<tr>
<td colspan=2><inpu t type="submit" name="submit" value="Add to Personal Info Table" />
<input type='reset' name='reset' value='Reset'></td>
</tr>
</table>
</center>
</form>
<?php
include ('./footer.php');
?>
</body>
</html>
[/code]
Comment