I am trying to enter the date in the database with an interval of 1 day, I use the following query

<?php $student = $_GET["student"]; $bookName = $_POST["bookName"]; $serialNum = $_POST["serial_num"]; $addQuery = "INSERT INTO book_week (student_id, book_name, serial_num, date_expiration) VALUES ('{$student}' , '{$bookName}', '{$serialNum}', '{$dateExpiration}' , 'DATE_ADD(NOW(), INTERVAL 1 DAY)'"; $addResult = mysqli_query($connection, $addQuery); } 

But the code does not work

Please help me fix the code.

  • And in what exactly does "not work" manifest itself? - Alexey Shimansky
  • Wow, I accidentally designed a Russian resource .... I don’t understand, the base just crashes, I used it without DATE_ADD (NOW (), INTERVAL 1 DAY) but I just put the number, and everything worked, but only in the database DATE values ​​were set to INT - pavel
  • Probably it is not necessary to do DATE_ADD() in single quotes. Without them at all. It should work as a MySQL function. - cyadvert
  • Just in case, did you connect to the database before executing the request? - Andrei Kuruljov
  • Yes, connected without a function with an INT value, everything works. I tried it without quotes, it does not work - pavel

1 answer 1

Your number of fields in insert does not match the number of values. And it also uses {$dateExpiration} , which is not advertised anywhere. And of course, the function should not be enclosed in quotes. And the closing parenthesis for values ​​should not be forgotten. Apparently it should be like this:

 $addQuery = "INSERT INTO book_week (student_id, book_name, serial_num, date_expiration) VALUES ('{$student}' , '{$bookName}', '{$serialNum}', DATE_ADD(NOW(), INTERVAL 1 DAY))";