Skip to content

SQL error when new record without age #9

Description

@mariodeckers

Hello Tania,
Playing around with your CRUD tutorial to try to understand it, I ran into this error SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '' for column `test`.`users`.`age` at row 1 when creating a new record without age field.
Even though field can be null in MySQL, it should probably not be empty..?
Anyway, this is my workaround: in create.php, set age to "null" if empty

            "firstname" => $_POST['firstname'],
            "lastname"  => $_POST['lastname'],
            "email"     => $_POST['email'],
            "age"       => (!strlen($_POST['age']) ? null : $_POST['age']),
            "location"  => $_POST['location']`

Liking your blog very much!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions