Get Date of Birth and Store it in Database using PHP
Get Date of Birth and Store it in Database using PHP
To get the date of birth, we are going to use an HTML form. And we will be using PHP to store it in the database.
Database of getting the Date of Birth and Store it in Database using PHP
Code of getting the Date of Birth and Store it in Database using PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | <!DOCTYPE html> <html> <head> <title></title> </head> <body> <form method="POST" action=""> <select name="Year"> <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> <select name="Month"> <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> <select name="Date"> <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; ?> </select> <input type="submit" name="sub"> </form> </body> </html> <?php $conn = mysqli_connect("localhost","root","","getdob"); if(isset($_POST['sub'])) { $Year = $_POST['Year']; $Month = $_POST['Month']; $Date = $_POST['Date']; if ($Year != '' && $Month != '' && $Date != '') { $date = $Year.'-'.$Month.'-'.$Date; $sql="INSERT INTO dob VALUES (Null,'$date')"; if (mysqli_query($conn,$sql)) { echo "Record added!"; } else { echo "Error!!!"; } } else { echo "Please Select Day, Month and Year!!!"; } } ?> |
Output:
Download Zip – GetDOBusingPHP