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: 
The problem is that the columns of the dates dont have a DEFAULT value and since while adding a record you dont define a value for the column it is giving an error. The solution is that either you give a value for the columns while adding the records or else alter the columns and give it a default value.

But your Table structure is not at all feasible to use. You should not have columns for individual dates. Like this you will have infinite columns in your table. So instead the solution is that you insert the date of the attendance marked with the rows you add.
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';

```