Inserting CURDATE() and CURTIME() in MySQL (PHP)
16,174
Solution 1
date
and time
are reserved words of mysql and hence should be quoted with backticks to avoid conflicting with reserved words.
"INSERT INTO `ordisp` (`date`, `time`, operator, ....
Solution 2
You have a syntax error - a comma on the end of the query:
'".$name."', '".$email."',)";
^ here
Remove it, so the full query becomes:
$query = "INSERT INTO `ordisp` (date, time, operator, status, completed, name, email) VALUES (CURDATE(), CURTIME(), '".$operator."', '".$status."', '".$complete."', '".$name."', '".$email."')";
For future debugging you should look at the MySQL error, it will give you a description of the problem, for example unknown field/table name or a syntax error etc etc.
Related videos on Youtube
Comments
-
I wrestled a bear once. almost 2 years
How do you insert
CURDATE()
andCURTIME()
in MySQL?I am inserting them into date and time fields, respectively in the DB table.
$query = "INSERT INTO `ordisp` (date, time, operator, status, completed, name, email) VALUES (CURDATE(), CURTIME(), '".$operator."', '".$status."', '".$complete."', '".$name."', '".$email."')";
Why isn't this working?
-
Rudi Visser over 11 yearsWhat isn't working? Do you have any errors? Is it perhaps because of your trailing
,
? Or perhaps because of reserved word usage? -
Bhavik Shah over 11 yearsPlease put errors that you get while using above mentioned code
-
-
Bhavik Shah over 11 yearsI dont think so. Refer this from Official MySql documentation. Please update your answer before it gets down-voted.
-
MrCode over 11 years
-
I wrestled a bear once. over 11 yearsI am using mysql 5.0, not 5.5. the backticks fixed it. Thanks user!
-
sunlight over 11 years@MrCode: True, These are no longer reserved words in
mysql 5.5
. I made a guess that he might be running onmysql 5.1
-
MrCode over 11 yearsThe backticks alone couldn't have solved this, even on MySQL 5.0 because of the syntax error. Strange - even the 5.0 docs say
date
andtime
are not reserved: dev.mysql.com/doc/refman/5.0/en/reserved-words.html