Jump to content

error with mySQL syntax, trying to create table


brem13

Recommended Posts

this is the error i'm getting "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 '-girl ( `id` INT( 50 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , `username` VARCHAR(' at line 1" when i run the page to create a user. here's the code i'm using, it happens sometimes, but not others, any help?

mysql_connect("$server", "$db_user", "$db_pass") or die(mysql_error());
mysql_select_db("singlese_messages") or die(mysql_error());
mysql_query("CREATE TABLE $username (
`id` INT( 50 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR( 75 ) NOT NULL ,
`subject` VARCHAR( 150 ) NOT NULL ,
`message` TEXT NOT NULL ,
`gift` VARCHAR( 50 ) NOT NULL,
`new` VARCHAR( 5 ) NOT NULL ,
`date_created` VARCHAR( 50 ) NOT NULL ,
`date_modified` VARCHAR( 50 ) NOT NULL 
)")  or die(mysql_error());  
mysql_close();

you could enclosed the username for the code to work

mysql_connect("$server", "$db_user", "$db_pass") or die(mysql_error());
mysql_select_db("singlese_messages") or die(mysql_error());
mysql_query("CREATE TABLE `$username` (
`id` INT( 50 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR( 75 ) NOT NULL ,
`subject` VARCHAR( 150 ) NOT NULL ,
`message` TEXT NOT NULL ,
`gift` VARCHAR( 50 ) NOT NULL,
`new` VARCHAR( 5 ) NOT NULL ,
`date_created` VARCHAR( 50 ) NOT NULL ,
`date_modified` VARCHAR( 50 ) NOT NULL
)")  or die(mysql_error()); 
mysql_close();

why is it a bad idea to have a separate table for each username, i figured that would be the best way, that way it doesnt have to search through a table full of everyones messages, only that user? how do you think i should make it, cuz this is the only way i know right now??

TEXT is in fact a variation of BLOB. It requires MySQL to split your data, because TEXT and BLOB columns are kept separately from rest of your data, due to their potentially very alrge size. Try to think of some reasonable limit for message size, and just use VARCHAR.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.