Im writing a PHP script which allows a user to create a Mysql table by filling in the values they want in a HTML form and then processing them into Mysql query.
This works fine however or one such table the user needs to be able to set numbers as the name of some of the table columns, this does not work and results in the below mysql error:
No TABLE created. Check 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 '45 double, 55 double, 45 double )' at line 5
The MySql looks like:
CREATE TABLE rates_
(
Weight int(11),
Length double,
Strength double,
Min double,
45 double,
55 double,
45 double
)
However when I create the table using phpMyAdmin the table is created fine, is there a special way to create tables with numbers as their column name?
Place backticks `
around the column names
CREATE TABLE rates_ (
`Weight` int(11),
`Length` double,
`Strength` double,
`Min` double,
`45` double,
`55` double
);
Also notice that 45
is used twice.