How to insert null values PHP/MYSQL

Viewed 45

I've started using mysql but I can't insert a null value into the table.

This is my simple code:

<?php

$pdo = new PDO('mysql:host=localhost; dbname=php_danki', 'root', '');

$sql = $pdo->prepare("INSERT INTO `clientes` VALUES (null, 'Samuel', 'Matos', '2017-05-09 19:00:00')");

$sql->execute();
?>

And that is the error I get:

Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'id' cannot be null

My table has 4 columns:

id (int), name (varchar), lastname (varchar), datatime (datatime)

Does someone know how to solve this problem?

My professor is busy now and he can't help me

0 Answers
Related