I am trying to insert a new row in my database with a date and the same date plus 1 week.
I use PDO in php, don't know if it is relevant.
This is the code which fails:
$stmtEncInsert = $db->prepare("INSERT INTO test
(id_Event, NIF, name , description, image, start_date, end_date)
VALUES (:idOfEvent, :NIF, :name, :description, :image, :startDate, DATE_ADD(:date_end,INTERVAL 1 WEEK)
)");
$stmtEncInsert->execute(array(':idOfEvent' => $idOfEvent, ':NIF'=> $NIF, ':name' => $resEnc['name'], ':description' => $resEnc['description'],
':image' => $resEnc['image'], ':startDate' => $date_end, ':date_end' => $date_end));
I get some data from other queries (example: $resEnc['..']) but all data is ok. I tried to print in a file all data and all of them are ok, they exist.
The problem is that the last field (end_date) is always giving error, always says: you cannot leave this field empty...
I think it is problem from DATE_ADD or so, but I haven't found anything related to this.
I tested deleting DATE_ADD and just using the current_date and it works so I guess this is the problem.
Any idea?
I use MySQL as engine
This is the output of the exception given:
Integrity constraint violation: 1048 Column 'end_date' cannot be null
$date_end contains 0000-00-00 it is a valid date and field is DATE type got from DB from another query