Lavonen
Lavonen

Reputation: 670

mySQL - cannot create table

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?

Upvotes: 0

Views: 49

Answers (1)

Pranav MS
Pranav MS

Reputation: 2296

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.

Upvotes: 2

Related Questions