jharker1987 Posted October 23, 2009 Share Posted October 23, 2009 Hi there, I am working on php based system. I have written a very simple insert command to update a table in my database. It is refusing to work. I have written thousands upon thousands of php/mysql lines of code over the years and this is the first time I have had this problem. Here is the code: $sql = "INSERT INTO '$guid' (DATE_TIME_UPDATE, ACCEPTED, DECLINED, MISSED, REQUESTED, TOTAL) VALUES ('$dt','$accepted','$declined','$missed','$requested','$totaldevices')"; It looks like this when ran: INSERT INTO '4c0ac655-41d1-4625-95bb-fe9a339728c5' (DATE_TIME_UPDATE, ACCEPTED, DECLINED, MISSED, REQUESTED, TOTAL) VALUES ('23/10/09 13:11:15','0','0','0','0','0') And the error looks like this: Failed; 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 ''4c0ac655-41d1-4625-95bb-fe9a339728c5' (DATE_TIME_UPDATE, ACCEPTED, DECLINED, MI' at line 1 its worth noting that I have verified the structure of the table and everything is solid. Any ideas what the problem is/could be? Quote Link to comment https://forums.phpfreaks.com/topic/178727-solved-mysql-insert-command-problem/ Share on other sites More sharing options...
trq Posted October 23, 2009 Share Posted October 23, 2009 Your table is seriously called 4c0ac655-41d1-4625-95bb-fe9a339728c5 ? Quote Link to comment https://forums.phpfreaks.com/topic/178727-solved-mysql-insert-command-problem/#findComment-942777 Share on other sites More sharing options...
jharker1987 Posted October 23, 2009 Author Share Posted October 23, 2009 unfortunately yes but this is very necessary. I am able to create the table using php-mysql create table, so i'm assuming its ok to use the insert command on it also? Quote Link to comment https://forums.phpfreaks.com/topic/178727-solved-mysql-insert-command-problem/#findComment-942784 Share on other sites More sharing options...
cags Posted October 23, 2009 Share Posted October 23, 2009 I could just be my screen, but it appears you have single quotes around your table name. These should either be replaced by backticks, or alternatively, since I'm fairly sure 4c0ac655-41d1-4625-95bb-fe9a339728c5 isn't a reserved word , just removed. Quote Link to comment https://forums.phpfreaks.com/topic/178727-solved-mysql-insert-command-problem/#findComment-942792 Share on other sites More sharing options...
PFMaBiSmAd Posted October 23, 2009 Share Posted October 23, 2009 Because the table name contains special characters that are not normally permitted in an identifier and it starts with a number, back-ticks would be required. However, since your table name appears to be some form of an id (from $guid) you likely have a serious design flaw. Quote Link to comment https://forums.phpfreaks.com/topic/178727-solved-mysql-insert-command-problem/#findComment-942799 Share on other sites More sharing options...
jharker1987 Posted October 23, 2009 Author Share Posted October 23, 2009 I could just be my screen, but it appears you have single quotes around your table name. These should either be replaced by backticks, or alternatively, since I'm fairly sure 4c0ac655-41d1-4625-95bb-fe9a339728c5 isn't a reserved word , just removed. using backticks solved the problem! big thanks! this has been really bugging me Quote Link to comment https://forums.phpfreaks.com/topic/178727-solved-mysql-insert-command-problem/#findComment-942804 Share on other sites More sharing options...
cags Posted October 23, 2009 Share Posted October 23, 2009 using backticks solved the problem! big thanks! this has been really bugging me Excellent. Don't forget to mark the topic as solved (button in the bottom left of the screen). Because the table name contains special characters that are not normally permitted in an identifier and it starts with a number, back-ticks would be required. I wasn't aware that '-' was a special character with regards to a table name, I'll bear that in mind for future reference. Just out of interested, I tried testing with a number at the start, it didn't seem to cause an issue without backticks, is this perhaps version dependent? Quote Link to comment https://forums.phpfreaks.com/topic/178727-solved-mysql-insert-command-problem/#findComment-942816 Share on other sites More sharing options...
PFMaBiSmAd Posted October 23, 2009 Share Posted October 23, 2009 The set of alphanumeric characters from the current character set, “_”, and “$” are not special... Exception: A reserved word that follows a period in a qualified name must be an identifier, so it need not be quoted... Identifiers may begin with a digit but unless quoted may not consist solely of digits. Anything else would need a back-tick. Quote Link to comment https://forums.phpfreaks.com/topic/178727-solved-mysql-insert-command-problem/#findComment-942823 Share on other sites More sharing options...
cags Posted October 23, 2009 Share Posted October 23, 2009 Identifiers may begin with a digit but unless quoted may not consist solely of digits. I see, excellent. Quote Link to comment https://forums.phpfreaks.com/topic/178727-solved-mysql-insert-command-problem/#findComment-942825 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.