PDA

View Full Version : CREATE TABLE issue


Tyler
January 26th, 2006, 04:05
I'm not too familiar with CREATE TABLE as I've always just done it through PMA, but not many are familiar with it and an install script is much easier.

What's weird is that it works on some PHP 4.4.x, and works perfectly on 5, so I have no idea what I am doing wrong. Here is what I'm doing:

$create_query = mysql_query("CREATE TABLE user(`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(255) NOT NULL,
`fname` VARCHAR(255) NOT NULL,
`lname` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL,
`password` VARCHAR(255) NOT NULL)");

Just one of the many variations I have tried. That ^^ returns an error of:

Error! Could not create table: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'user(`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY, `user

Any help is highly appreciated as I've been working at this for days with no luck. Thanks!

Anoop
January 26th, 2006, 05:04
The error that you get is a MySql error. So we have nothing to do with php, I think. The query is working fine with mysql versions 4.1.14-max and 5.0.18-max.

Which version of mysql are you using ?

Tyler
January 26th, 2006, 05:08
MySQL 4.1.16-nt running on 127.0.0.1 as root@localhost

But it works fine for me just not some of the users. Should I tell them to upgrade MySQL or is there a way I can perfect the query for it to work on all versions?

Anoop
January 26th, 2006, 05:13
Just try this query instead :


$create_query = mysql_query("CREATE TABLE `user`
(`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(255) NOT NULL,
`fname` VARCHAR(255) NOT NULL,
`lname` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL,
`password` VARCHAR(255) NOT NULL)");


The only modification I made is to enclose the table name user with back tick (`). It'll escape the keywords in the query.

Digiscape
January 26th, 2006, 05:14
Try adding back ticks to the table name: `user`

Regards
Jason

Digiscape
January 26th, 2006, 05:16
Anoop beat me to it :roll:

Anoop
January 26th, 2006, 05:21
Anoop beat me to it :roll:

Jason, I'm sorry for that :D

Tyler
January 27th, 2006, 21:08
Sorry for the lack of update, I was testing to make sure. The two users who tried it now, got it working. Thanks again! :D