Reputation: 171
I have a createAdmin.php form with this section:
<p>Date of Birth: <input maxlength="4" size="4" type = "text" name = "year" value = "" placeholder="YYYY" > -
<input maxlength="2" size="2" type = "text" name = "month" value = "" placeholder="MM" > -
<input maxlength="2" size="2" type = "text" name = "day" value = "" placeholder="DD" >
Caching those values:
$year = (int) $_POST['year'];
$month = (int) $_POST['month'];
$day = (int) $_POST['day'];
And finally passing to mySQL:
$formBirth = "{$year}{$month}{$day}";
$createAdmin = mysqli_query($db, "INSERT INTO admins (username, hashed_pwd, power, email, name, birth) VALUES (
'{$username}', '{$password}', '{$power}', '{$email}', '{$realName}', STR_TO_DATE('$formBirth', '%Y%m%d'))");
This method apparently doesn't work. Any ideas?
Upvotes: 0
Views: 156
Reputation: 9322
Try to add /
on this one:
$formBirth = $year."/".$month."/".$day;
Or:
$formBirth = "{$year}/{$month}/{$day}";
Or using -
$formBirth = $year."-".$month."-".$day;
Or:
$formBirth = "{$year}-{$month}-{$day}";
See Demo
Upvotes: 0
Reputation: 310
Date of birth<input type="date" name="date" />(html 5)
<?php
$formBirth = $_POST['date'];
$createAdmin = mysqli_query($db, "INSERT INTO admins (username, hashed_pwd, power, email, name, birth) VALUES (
'{$username}', '{$password}', '{$power}', '{$email}', '{$realName}',{$formBirth})");
?>
OR use this
<?php
$year =$_POST['year'];
$month =$_POST['month'];
$day =$_POST['day'];
$formBirth=$year."/".$month."/".$day;
?>
Upvotes: 0
Reputation: 286
Try to take all these into a variable and use that
$date = $year.'-'.$month.'-'.$day;
Upvotes: 1