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: 
> 
> So I use dates as column names.
> 
> 
> 

...bad idea, because you theoretically have an infinite number of columns, if the system is used long term. And it will make it very difficult to write certain types of query to understand the data.

> 
> So I guess the structure of my db must be the problem
> 
> 
> 

...essentially, yes.

To understand how to design your database correctly, you should learn about [database normalisation](https://www.studytonight.com/dbms/database-normalization.php).

In this scenario I'd suggest you'd have one table for the list of all people, and another for the list of all classes.

If you're running a predetermined timetable, you might then have a table which lists the class, the date and the teacher assigned to that date & class. (Or you might assign the teacher in the classes table, if one teacher normally takes the whole class.)

Then lastly you'd have a separate "attendance" table which contains columns "personID" and "attendanceDate", and "classID".

That way you will end up with multiple rows in there with the same person / class combination and different dates, to record all their attendances at each class and each date of that class. And it's completely extendable, infinitely, without you needing to modify the tables each time a new class or date is announced, or needing to dervice column names in your code when trying to generate a query.
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