I would like to add column to my MySQL-database with spaces.
In terms of SO-questions this is as close as I've come Insert data in 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 code below:
mysqli_query($db, "ALTER TABLE msrk_krit ADD 'test 1' VARCHAR( 255 )")
But I get this error code:
Error description: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1 VARCHAR( 255 )' at line 1
Any ideas?
Thanks
Do this:
mysqli_query($db, "ALTER TABLE msrk_krit ADD `test 1` VARCHAR( 255 )")
Notice that the single quotes around test 1 are actually back ticks, not quote marks.
Honestly though, you should avoid using spaces in your column names, it will be easier to maintain in the long run.
(Documentation: mysqli_query
)
mysqli_query($db, "ALTER TABLE `msrk_krit` ADD `test 1` VARCHAR(255)")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With