mysql - I want to alter table in php , but my code is not working -


i want add column table using php code not working

$sql="alter table user_preference_table add column '$tag_id' varchar(60) "; $result = $conn->query($sql); 

i think problem way of declaring variable query ?

is query right?

'$tag_id'  

it variable contains id 501

replace single quote backtick.

$sql="alter table user_preference_table add column `$tag_id` varchar(60) "; 

signle quotes inserting values database tables.

backticks used db fields.

they prevent errors of using reserved keywords in mysql.

e.g.

as  ...etc 

Comments

Popular posts from this blog

how to display 2 form fields on same line with bootstrap -

How do you convert a timestamp into a datetime in python with the correct timezone? -