0

whats my problem to add new columns to DB

//  Connection
global $tutorial_db;

$tutorial_db = new mysqli();
$tutorial_db->connect($dbhost, $dbuser, $dbpass, $dbname);
$tutorial_db->set_charset("utf8");

//  Check Connection
if ($tutorial_db->connect_errno) {
    printf("Connect failed: %s\n", $tutorial_db->connect_error);
    exit();
}
    $query="alter table groups add order varchar (20)";
    $result = $tutorial_db->query($query);

This code doesn't do anything...

3 Answers 3

3

ORDER is a reserved word, you need to quote it with backticks, or use a different name for the column.

$query="alter table groups add `order` varchar (20)";
Sign up to request clarification or add additional context in comments.

Comments

0

I suspect it's because your column is called 'order', which is an SQL keyword. If you really want to call it order, enclose it with backticks -

$query="alter table groups add `order` varchar (20)";

But I'd recommend you call it something else if you can.

Comments

0
ALTER TABLE `table_name` add COLUMN `column_name` VARCHAR(20);

Please note the backticks. They are important to escape the column name, especially if you wish to call your column order as that is already a reserve word in mysql and has it's own meaning.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.