I am a little new to MySQL (came from MS SQL) and recently encountered something very confusing for me when trying to insert INSERT values ββin a database.
I created the INSERT SQL command through PHP, but found that an error occurred while trying to execute it.
INSERT INTO myTableName (first-name, last-name) VALUES ('Ted', 'Johnson')
To my way of thinking, the above line should work. But this is not so. I even tried using it directly in phpMyAdmin, but I got the same syntax error.
The only thing that ended up making it work was that I surrounded the field names in the SQL expression with the "backtick" or "accent" symbol (another symbol on the tilde on the keyboard). For instance...
INSERT INTO myTableName(`first-name`, `last-name`) VALUES ('Ted', 'Johnson')
I never knew that it was necessary in MySQL or MS SQL Server. I always simply listed the names of the fields without limiting them. Has anyone come across this before? I am using MySQL 5.0.77. Thanks.
source share