MySQL add column with spaces in php
I would like to add a column to my MySQL database with spaces.
In terms of SO questions, this is as close as I came to Insert data into mysql colum with spaces with php
In php MyAdmin I can write the code
ALTER TABLE `msrk_krit` ADD `test 1` VARCHAR(255)
However, in php, I am trying to use the following code:
mysqli_query($db, "ALTER TABLE msrk_krit ADD 'test 1' VARCHAR( 255 )")
But I am getting this error code:
Error Description: 1064 You have an error in your SQL syntax; check the manual corresponding to the MariaDB server version for the correct syntax to use next to "1 VARCHAR (255)" on line 1
Any ideas?
thank
Do it:
mysqli_query($db, "ALTER TABLE msrk_krit ADD `test 1` VARCHAR( 255 )")
Note that the single quotes around Test 1 are actually back ticks, not quotes.
To be honest, you should avoid using spaces in column names, they will be easier to maintain in the long run.
mysqli_query($db, "ALTER TABLE `msrk_krit` ADD `test 1` VARCHAR(255)")
mysqli_query($db, "ALTER TABLE msrk_krit ADD 'test 1' VARCHAR( 255 )")
it should be
mysqli_query($db, "ALTER TABLE msrk_krit ADD `test 1` VARCHAR( 255 )")