there were a lot of answers related to this, but I couldn\'t find useful information. I\'m trying to connect to the database and insert user\'s entered values into it, but I
The error seems quite clear. You have a column in the table that cannot take on a NULL
value.
I would speculate that it is not one of the column where you are explicitly providing a value (name
, surname
, employment_date
). You need to look at the definition of the table and look for another column defined as NOT NULL
(or perhaps PRIMARY KEY
with no default value).
Make sure that the column is marked as Primary key or auto_increment if you are using it that way, or mark it as null if you want to store null.
It could be any problem related to the field. Check the HTML for spelling, confusion between name and value, etc. Your field may be empty because it is not finding the value you actually entered in the field because there is no such field per code (only on your screen). In my case, I had
$new_user = array(
"id" => $_POST ['id'],
"fname" => $_POST['firstname']
But the HTML was using fname and fname for both value and name.
And there was the first error: name="firstname" was written as vname="firstname" Then the confusion with name and HTML value.
You didn't post your HTML. The error is perhaps there.