'PHP MYSQL UPDATE DATE column with input type date?
Just a simple DATE with an input type Date and I want to UPDATE a DATE column in MySQL WITH PHP. (I SEE LOTS OF ANSWERS FOR DATETIME, I JUST WANT TO INSERT DATE LIKE: '1980-07-23')
$dobdate = date('Y-m-d', strtotime(str_replace('-', '/', $_POST["dob"])));
$dob = $DBConnection->quote($dobdate);
$sql = "UPDATE `userinfo` SET dob = ? WHERE id = ?";
$stmt = $DBConnection->prepare($sql);
$stmt->execute([$dob, $_SESSION["id"]]);
My dob column is only getting: 0000-00-00
Solution 1:[1]
Try This it works for me
$dobdate = date('Y-m-d', strtotime(str_replace('-', '/', $_POST["date"])));
$sql = $DBConnection->prepare("UPDATE userinfo SET dob=:dob WHERE id=:id");
$sql->execute([
'dob' => $dobdate,
'id'=>$_SESSION["id"]
]);
or remove this line
$dob = $DBConnection->quote($dobdate);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
