f.ismayil Posted April 17, 2011 Share Posted April 17, 2011 I have MySQL table with the following fields: user=>varchar product=>varchar Amount=>int Date=>date Note=>tinytext I can't add value to these field by the following php code: $date = date("Y.m.d"); $query = "INSERT INTO order VALUES ('farhad', 'Mango', '10', '$date', 'hello')"; $result = mysql_query($query) or die(mysql_error()); I receive the following warning: Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for '2.0/DST' instead in C:\inetpub\wwwroot\Okern\~order.php on line 10 Call Stack: 0.0047 325856 1. {main}() C:\inetpub\wwwroot\Okern\~order.php:0 0.0274 344912 2. date() C:\inetpub\wwwroot\Okern\~order.php:10 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order VALUES ('farhad', 'Mango', '10', '2011.04.17', 'hello')' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/233957-adding-data-into-mysql-table/ Share on other sites More sharing options...
gristoi Posted April 17, 2011 Share Posted April 17, 2011 $date = date('Y-m-d'); Use - not . Quote Link to comment https://forums.phpfreaks.com/topic/233957-adding-data-into-mysql-table/#findComment-1202543 Share on other sites More sharing options...
f.ismayil Posted April 17, 2011 Author Share Posted April 17, 2011 The following code is also not working: $query = "INSERT INTO order VALUES ('farhad', 'Mango', '10', '2011-04-10', 'hello')"; $result = mysql_query($query) or die(mysql_error()); Gives the following message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order VALUES ('farhad', 'Mango', '10', '2011-04-10', 'hello')' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/233957-adding-data-into-mysql-table/#findComment-1202562 Share on other sites More sharing options...
PFMaBiSmAd Posted April 17, 2011 Share Posted April 17, 2011 order, the part of the query that is being pointed out in the error messages, is a reserved mysql keyword. You either need to enclose it in back-ticks `order` every time you use it as your table name or you need to rename your table to something else. Quote Link to comment https://forums.phpfreaks.com/topic/233957-adding-data-into-mysql-table/#findComment-1202563 Share on other sites More sharing options...
f.ismayil Posted April 17, 2011 Author Share Posted April 17, 2011 Thank you very much PFMaBiSmAd. I changed table name into 'orders' and everything started working Quote Link to comment https://forums.phpfreaks.com/topic/233957-adding-data-into-mysql-table/#findComment-1202567 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.