0

I have this SQL code I have used on another server to create a table if it doesn't exist. It has always worked perfectly. Today I decided to install mySQL on my own computer and use the same script, but this time I get an error. I have tried to rewrite the code in case there are any compatibility issues, however, without any success...

The SQL code:

$table  =  "Test";

$sql = "CREATE TABLE IF NOT EXIST $table (
        id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
        Name VARCHAR(30) NOT NULL,
        Email VARCHAR(50) NOT NULL,
        Country VARCHAR(50) NOT NULL,
        Date TIMESTAMP
        )";

This is the error message i receive:

Error creating table: 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 'EXIST Test ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, ' at line 1

I tried to create a new table manually in phpMyAdmin and simply copy the generated SQL code to my PHP-script and create a table that way. It didn't work either...

It's mariaDB on a Kali computer:

mysql version 15.1 Distrib 10.1.29-MariaDB, for debian-linux-gnu (i686) using readline 5.2

Any ideas?

0

1 Answer 1

2

I think you have made one spelling mistake in EXIST should write like EXISTS

Please re write your query as

$sql = "CREATE TABLE IF NOT EXISTS  $table (
        id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
        Name VARCHAR(30) NOT NULL,
        Email VARCHAR(50) NOT NULL,
        Country VARCHAR(50) NOT NULL,
        Date TIMESTAMP
        )";

this will surely work in your case please try this.

Sign up to request clarification or add additional context in comments.

2 Comments

This must be the most embarrassing question I have ever created on this forum... Your answer was, of course, correct and it solved the problem. I have literally been trying to solve this problem the whole morning and came to the conclusion that this must be some "unique comparability problem" :S Thanx a lot ! :)
@Lavonen please carefully read the error message. You will definitely find the answer. If the above answer solves your problem please accept the answer.Then only the newbies can find the answer easily. Thanks.

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.