thecodeholic / php-crash-course-2020

235 stars 228 forks source link

"Uncaught PDOException: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect decimal value: '' for column `products_crud`.`products`.`price` at row 1" #6

Open frankndungu opened 2 years ago

frankndungu commented 2 years ago

If you are a beginner following this tutorial in 3:17:42 after you refresh your server you will encounter this error.

How to bypass this error is to simply declare an if empty statement before the $pdo prepared statement, it should look like this;

if (empty($errors)) {

        $statement = $pdo->prepare("INSERT INTO products (title, image, description, price, create_date)
        VALUES (:title, :image, :description, :price, :date)");
        $statement->bindValue(':title', $title);
        $statement->bindValue(':image', '');
        $statement->bindValue(':description', $description);
        $statement->bindValue(':price', $price);
        $statement->bindValue(':date', $date);
        $statement->execute();
    }

your code should run and you will see the form validation.

frankndungu commented 2 years ago

This worked well for me.