Paul-D Posted August 8, 2018 Share Posted August 8, 2018 DROP TABLE IF EXISTS `rain-accounts`; CREATE TABLE IF NOT EXISTS `rain-accounts` ( `rainID` varchar(10) DEFAULT NULL, `AccountDate` varchar(10) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO rain-accounts (rainID , AccountDate) VALUES ('5b6acefb' , '2018-08-08'); It was originaly INSERT INTO rain-accounts (rainID , date) VALUES ('5b6acefb' , '2018-08-08'); But I thought that you may not be able to have a field called date. Quote Link to comment https://forums.phpfreaks.com/topic/307598-cant-get-this-sql-code-to-insert/ Share on other sites More sharing options...
Barand Posted August 8, 2018 Share Posted August 8, 2018 (edited) The problem is your table name. To be more precise, the "-" in the name casue it to be interpreted as "rain minus accounts". You need backticks around the name (or avoid hyphens in favour of underscores in identifiers). Use DATE type, not varchar, for dates. Even though "date" is keyword, and better avoided, it would have been accepted as it is not reserved. mysql> DROP TABLE IF EXISTS `rain-accounts`; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> CREATE TABLE IF NOT EXISTS `rain-accounts` ( -> `rainID` varchar(10) DEFAULT NULL, -> `AccountDate` varchar(10) DEFAULT NULL -> ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Query OK, 0 rows affected (0.15 sec) mysql> INSERT INTO rain-accounts (rainID , AccountDate) VALUES ('5b6acefb' , '2018-08-08'); ERROR 1064 (42000): 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 '-accounts (rainID , AccountDate) VALUES ('5b6acefb' , '2018-08-08')' at line 1 Edited August 8, 2018 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/307598-cant-get-this-sql-code-to-insert/#findComment-1560286 Share on other sites More sharing options...
requinix Posted August 8, 2018 Share Posted August 8, 2018 Consider a simple underscore instead of the hyphen. Or nothing at all and just have it as one word. Quote Link to comment https://forums.phpfreaks.com/topic/307598-cant-get-this-sql-code-to-insert/#findComment-1560298 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.