0

Hej.

I get this error message when execute my code? I post value "2020-12-19" $data_input_textfield = $_POST["date"]; from my form. cant figure out where 1989 comes from...

Message:

Exception has occurred.
PDOException: SQLSTATE[HY000]: General error: 1525 Incorrect DATE value: '1989'

The code:

$sql = "CALL booking_date_input($data_input_textfield)";
    $stmt = $dbh->getInstance()->prepare($sql);
    $stmt->execute();
    $date=$stmt->fetch();

Best regards /Svante

  • 1
    Quote marks needed round the date string in the brackets of the CALL command would be my guess – ADyson Jan 02 '21 at 10:12
  • Now you insert arithmetic expression: `2020-12-19` = `1989`. You must insert `'2020-12-19'`. – Akina Jan 02 '21 at 10:18
  • 2
    You are using a `Prepared Statement` so why not do it properly and pass in a placeholder in the sql expression rather than embedding a string variable directly – Professor Abronsius Jan 02 '21 at 10:19

1 Answers1

3

You can try a slightly different approach whereby you supply a placeholder to the sql command and execute the statement with the variable bound to that placehoolder - like so:

$sql = "CALL `booking_date_input`(:date);";
$stmt = $dbh->getInstance()->prepare($sql);
$stmt->execute(array(':date'=>$data_input_textfield));
$date=$stmt->fetch();
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
  • 1
    Thank you. I found my issue. I had forgotten one ; in `$sql = "CALL `booking_date_input` (:date_input);";` That made all the differens and now it work. Added the placegholder offcource as you suggested. `$stmt->bindParam(':date_input', $date_input, PDO::PARAM_STR);`. – Svante Stenberg Jan 02 '21 at 22:24