- I have a form with a date field.
- I select a date using a jquery datepicker. The format is mm/dd/yyyy.
- The date inserts into the db like 0000-00-00.
- When I use die($startdate); This outputs the correct date in the correct format when uncommented.
db type: date
Code:
$startdate = date('Y-m-d', strtotime($_POST['startdate']));
//die($startdate); //<--outputs the correct date in the correct format when uncommented.
try {
$stmt = $db->prepare('INSERT INTO table (firstname,lastname,startdate) VALUES (:firstname, :lastname, :startdate)');
$stmt->execute(array(
':firstname' => $_POST['firstname'],
':lastname' => $_POST['lastname'],
':startdate' => $_POST['startdate'],
));
}
I also tried
$startdate = date('Y-m-d', strtotime($_POST['startdate']));
in the try{} but doesn't work either.
What am I doing wrong?
This is to John Conde. I believe it's quite simple on how this is different and why it's not a duplicate. If you didn't notice there was an "ERROR" in my code. I needed help finding the issue. Marc found it and now it works. I still wonder why this is so difficult to understand.