Steven Trainor Steven Trainor - 2 years ago 73
SQL Question

How to add new column to MYSQL table

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

assessmentid | q1 | q2 | q3 | q4 | q5

Say I have a page with a textbox and i type q6 in to the textbox and press a button then the table is updated to

assessmentid | q1 | q2 | q3 | q4 | q5 | q6

Thanks in advance

include 'core/init.php';
include 'core/admininit.php';
include 'includes/overall/overall_header.php';
include 'includes/adminmenu.php';

mysql_query("ALTER TABLE `assessment` ADD newq INT(1) NOT NULL AFTER `q10`");

<h1>Input Career Name</h1>

<form method="post" action="">

Career Name
<input type="text" name="newq" size="20">

<input type="submit"
name="submit" value="Submit">


Answer Source

your table:

q1 | q2 | q3 | q4 | q5

you can also do

ALTER TABLE yourtable ADD q6 VARCHAR( 255 ) after q5
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download