Saturday, 27 July 2013

Date Of Birth in php


DATE OF BIRTH
Date Of Birth
In the date of birth we are going to use for loop condition and these values are inserted into database in the form of  $dob=$date1."-".$month1."-".$year1;  Lets see the example for date of birth in php.




<form name="aform" method="post" onsubmit="return validation();">
<table border="0px" cellpadding="10" cellspacing="0" width="40%" id="tbl">
<tr><td colspan="4" align="center">DATE OF BIRTH</td></tr>
<tr>
     <td>Date Of Birth</td>
     <td>
           <select name="date1">
                 <option value="">Date</option>
                 <?php
                 for($s=01; $s<=31; $s++)
                 {
                 
                 ?>
                 <option value="<?php echo $s; ?>"><?php echo $s; ?></option>
                 <?php
                 }
                 ?>
                 
           </select>
    </td>
    <td>
        <select name="month1">
           <option value="">month</option>
           <option value="january">January</option>
           <option value="febuary">Febuary</option>
           <option value="march">March</option>
           <option value="april">April</option>
           <option value="may">May</option>
           <option value="june">June</option>
           <option value="july">July</option>
           <option value="august">August</option>
           <option value="september">September</option>
           <option value="october">October</option>
           <option value="november">November</option>
           <option value="december">December</option>
        </select>
    </td>
    <td>
        <select name="year1">
            <option value="">Year</option>
      <?php
                 for($d=2013; $d>=1966; $d--)
                 {
                 
                 ?>
                 <option value="<?php echo $d; ?>"><?php echo $d; ?></option>
                 <?php
                 }
                 ?>
     
         </select>
         
    </td>
    
</tr>
<tr>
     <td colspan="4" align="center"><input type="submit" name="submit" value="submit" /></td>
</tr>
</table>
</form>

Lets see how the three values ie date,month,and year are inserted in the single field in the database and fetch the values from the database.


<?php

$connect=mysql_connect("127.0.0.1","root","") or die(mysql_error());
$select_db=mysql_select_db("dob_db",$connect);
if(isset($_POST['submit']))
{
$date1=$_POST['date1'];
$month1=$_POST['month1'];
$year1=$_POST['year1'];
$dob=$date1."-".$month1."-".$year1;
$insert=mysql_query("insert into dob1_tbl(dob,last_update)values('$dob',now())",$connect) or die(mysql_error());
if($insert)
{
echo"<script> alert('inserted')</script>";
}

}
?>

Here the date,month and year are inserted in the single field using the code ."_".  then the output will be the