Hello,
I created a form. A drop down list for the person to select his date-of-birth, YYYY-MM-DD, then add it into the database with all his other particulars.
Problem is, I dont know how to insert the date. Because in my database, it will show 0000-00-00.
This is my code to select the DOB from 3 drop down menus.
Code:
<?php
echo "<select name='day'>";
for ($x=1; $x<=31; $x++) {
echo "<option value=$x>$x</option>";
}
echo "</select>";
echo "<select name='month'>";
for ($x=1; $x<=12; $x++) {
echo "<option value=$x>$x</option>";
}
echo "</select>";
echo "<select name='year'>";
for ($x=2008; $x>=1930; $x--) {
echo "<option value=$x> $x </option>";}
echo "</select>";
?>
Code:
<?php
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
//my attempt to convert a single digit into double digits for the month and day 1-9
if($month > 1 && $month <10){$month = '0' . $month;}
if($day > 1 && $day < 10){$day = '0' . $day;}
$dob = $year."-".$month."-".$day;
?>
Code:
//Prepare the Insert Statement
$stmt = $mysqli->prepare("INSERT INTO User
VALUES (?,?,?,?,?,?)");
//Bind the values
//I think the "d" in "sdssss" should stand for date right?
$stmt->bind_param("sdssss", $email, $dob, $password, $fname,
$lname, $gender);
When I used command prompt to check my DOB, they were all 0000-00-00. Help please! =/