i m facing problem regarding storing DOB of employee into database using html form
m using date as a datatype and in database format for date is yy-mm-dd....
all other fields are properly working and storing into database but dob filed shown empty....

    <head><title> Employee Data</title></head>
  <body bgcolor="pink">
  <form method="POST" action="empprins.php">
   <h3> <p align="center"> Employee Personal Detail </h3>   </p>
      <table <p align="center">
   <tr> <th>Employee Code :</th><td> <input type="text" name="ecode" size="20"/></td></tr>
  <tr><th>Employee Name: </th><td><input type="text" name="ename" size="20"/>       </td></tr>
 <tr><th> Employee Education:</th><td> <input type="text"  name="eedu" size="20">   </td></tr>
 <tr><th> Gender:</th><td> Male<input type="radio" name="egender" value="Male"></td>
 <td> Female<input type="radio" name="egender" value="female"></td></tr>
  <tr> <th>DOB <td>
  <select size="1" name="edob" value="Year">
  <select size="1" name="edob" value="month">  </th>
<select size="1" name="edob" value="date">
</select> </td></tr>
<tr><th>Father/Husband Name:</th><td><input type="text" name="ef_hname" size="20"></td></tr>
<tr><th>Father/Husband Occu:</th><td><input type="text"  name="ef_hoccu" size="20"></td></tr>
<tr><th> Address1:</th><td><textarea rows="2" cols="20" name="eadd1"> </textarea></td></tr>
<tr><th> Adreess2:</th><td><textarea rows="2"  cols="20" name="eadd2" ></textarea></td></tr>
<tr><th> City </th><td><select size="1" name="ecity" value=""> <BR>
<tr><th> State:</th><td><select size="1" name="esta" value="">
</select></td></tr> <BR>
<tr><th>Pin No:</th> <td> <input type="text" name="epin" size="20">   </td></tr>
<tr><th>Contact No:</th> <td> <input type="text"  name="etel" size="20">   </td></tr>
 </p> </table>
  <input type="submit" value="SAVE">

 <TITLE>New Document</TITLE>
 $ecode = $_POST["ecode"];
 $ename = $_POST["ename"];
$edob =$_POST["edob"];
$eedu =$_POST["eedu"];

$con = mysql_connect("localhost","root","root");
 if (!$con)
  die('Could not connect: ' . mysql_error());
  mysql_select_db("master", $con);

 $query="INSERT INTO emp_personal  VALUES  ('$ecode','$ename','$edob','$egender','$eedu','$ef_hname', '$ef_hoccu','$eadd1','$eadd2','$ecity','$esta', '$etel','$epin')";
   if (mysql_query($query, $con))
echo "record added!";

echo "something went wrong";
7 Years
Discussion Span
Last Post by tomatocms

Try this:

1) Make a HTML more clear by using three separated fields for DOB filed:

<select name="yearOfBirth">
  <option value="">---Select year---</option>
  <?php for ($i = 1980; $i < date('Y'); $i++) : ?>
  <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
  <?php endfor; ?>

<select name="monthOfBirth">
  <option value="">---Select month---</option>
  <?php for ($i = 1; $i <= 12; $i++) : ?>
  <option value="<?php echo ($i < 10) ? '0'.$i : $i; ?>"><?php echo $i; ?></option>
  <?php endfor; ?>

<select name="dateOfBirth">
  <option value="">---Select date---</option>
  <?php for ($i = 1; $i <= 31; $i++) : ?>
  <option value="<?php echo ($i < 10) ? '0'.$i : $i; ?>"><?php echo $i; ?></option>
  <?php endfor; ?>

2) Get the posted data:

$yearOfBirth = $_POST['yearOfBirth'];
$monthOfBirth = $_POST['monthOfBirth'];
$dateOfBirth = $_POST['dateOfBirth'];

// Validate
if ($yearOfBirth != '' && $monthOfBirth != '' && $dateOfBirth != '') {
  // Generate date of birth in format of YYYY-mm-dd
  $date = $yearOfBirth.'-'.$monthOfBirth.'-'.$dateOfBirth;
  // Then insert to database as normal
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.