Question: I have a problem inserting data into my MySQL database.
The structure of the db looks like this:

```
id | name | class |  23-02-2022 | 26-02-2022 | and so on ...

```

The databse is part of an attendance system. So I use dates as column names.

I use this code to open a csv file and upload some data into the db. As you can see in this part of the code I only put datas in the name and class column.

```
if (($handle = fopen("class.csv", "r")) !== FALSE)
{
    while (($data = fgetcsv($handle, 1000, ";")) !== FALSE)
    {

        $query="INSERT INTO table21228 (name, class) VALUES ('$data[0]' , '$data[1]')";
        if ($conn->query($query) === TRUE) {
        }
        else {
        echo 'Error: '. $conn->error;
        } fclose($handle);
     }

```

I get this error message: *Error: Field '23-02-2022' doesn't have a default value*

When I use a different table, where the only columns are id, name, class it works without any problems.
So I guess the structure of my db must be the problem

Maybe all those dates columns like 23-02-2022???

Hope some might help me. Thank you!

Kind regards
Dan

Answer: 
Could be you have a table with not null columns and you try to insert a row without a proper value for the not nullable columns .. the you have the message for field '23-02-2022' doesn't have a default value

the try insert a proper value for these columns

```
$query="INSERT INTO table21228 (name, class, `23-02-2022`, `26-02-2022` ) VALUES ('$data[0]' , '$data[1]', '2022-02-20', '2022-02-20')";

```

or try revoke the not null constranits for theese columns

```
alter table table21228  modify column `23-02-2022` date;

```

or set a default value

```
ALTER TABLE table21228 MODIFY column `23-02-2022` date DEFAULT '2022-02-20';

```
first check your csv file has the right amount of columns as your database then set your columns default to from not NULL to null or none