How to add new column to MYSQL table?

后端 未结 8 1734
南旧
南旧 2020-11-27 12:38

I am trying to add a new column to my MYSQL table using PHP. I am unsure how to alter my table so that the new column is created. In my assessment table I have:



        
8条回答
  •  情歌与酒
    2020-11-27 13:34

    Based on your comment it looks like your'e only adding the new column if: mysql_query("SELECT * FROM assessment"); returns false. That's probably not what you wanted. Try removing the '!' on front of $sql in the first 'if' statement. So your code will look like:

    $sql=mysql_query("SELECT * FROM assessment");
    if ($sql) {
     mysql_query("ALTER TABLE assessment ADD q6 INT(1) NOT NULL AFTER q5");
     echo 'Q6 created'; 
    }else...
    

提交回复
热议问题