brem13 Posted May 27, 2010 Share Posted May 27, 2010 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(); Quote Link to comment https://forums.phpfreaks.com/topic/203093-error-with-mysql-syntax-trying-to-create-table/ Share on other sites More sharing options...
brem13 Posted May 27, 2010 Author Share Posted May 27, 2010 the part in the error "-girl" is part of the username thats used to create the table name Quote Link to comment https://forums.phpfreaks.com/topic/203093-error-with-mysql-syntax-trying-to-create-table/#findComment-1064161 Share on other sites More sharing options...
brem13 Posted May 27, 2010 Author Share Posted May 27, 2010 i tried it again, without the dash in the username and used an underscore instead and that worked, hmmmm??? Quote Link to comment https://forums.phpfreaks.com/topic/203093-error-with-mysql-syntax-trying-to-create-table/#findComment-1064165 Share on other sites More sharing options...
riwan Posted May 31, 2010 Share Posted May 31, 2010 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(); Quote Link to comment https://forums.phpfreaks.com/topic/203093-error-with-mysql-syntax-trying-to-create-table/#findComment-1065573 Share on other sites More sharing options...
Mchl Posted May 31, 2010 Share Posted May 31, 2010 Seriously? A separate table for each user? That is not a good idea. Quote Link to comment https://forums.phpfreaks.com/topic/203093-error-with-mysql-syntax-trying-to-create-table/#findComment-1065576 Share on other sites More sharing options...
Anzeo Posted May 31, 2010 Share Posted May 31, 2010 As Mchl points out, why are you creating a seperate table for each user? I suggest making one USER table (with the same create statement) and then inserting each user as a row into it. Quote Link to comment https://forums.phpfreaks.com/topic/203093-error-with-mysql-syntax-trying-to-create-table/#findComment-1065591 Share on other sites More sharing options...
ignace Posted May 31, 2010 Share Posted May 31, 2010 i tried it again, without the dash in the username and used an underscore instead and that worked, hmmmm??? Surround it with ` and it will work. Otherwise the dash (-) is seen as an operator. Quote Link to comment https://forums.phpfreaks.com/topic/203093-error-with-mysql-syntax-trying-to-create-table/#findComment-1065627 Share on other sites More sharing options...
brem13 Posted May 31, 2010 Author Share Posted May 31, 2010 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?? Quote Link to comment https://forums.phpfreaks.com/topic/203093-error-with-mysql-syntax-trying-to-create-table/#findComment-1065656 Share on other sites More sharing options...
Mchl Posted May 31, 2010 Share Posted May 31, 2010 It's a bad idea, because it will put (a lot) more stress on your database, than having just one table. http://www.phpfreaks.com/blog/giuseppe-maxia-on-database-normalisation-and-smoking Quote Link to comment https://forums.phpfreaks.com/topic/203093-error-with-mysql-syntax-trying-to-create-table/#findComment-1065659 Share on other sites More sharing options...
brem13 Posted May 31, 2010 Author Share Posted May 31, 2010 duly noted, thanks dude Quote Link to comment https://forums.phpfreaks.com/topic/203093-error-with-mysql-syntax-trying-to-create-table/#findComment-1065694 Share on other sites More sharing options...
Mchl Posted May 31, 2010 Share Posted May 31, 2010 Some more hints: `date_created` VARCHAR( 50 ) NOT NULL , `date_modified` VARCHAR( 50 ) NOT NULL use MySQL's DATE datatype `message` TEXT NOT NULL , Won't VARCHAR(65000) be anough? Quote Link to comment https://forums.phpfreaks.com/topic/203093-error-with-mysql-syntax-trying-to-create-table/#findComment-1065695 Share on other sites More sharing options...
brem13 Posted May 31, 2010 Author Share Posted May 31, 2010 varchar(65000)? Quote Link to comment https://forums.phpfreaks.com/topic/203093-error-with-mysql-syntax-trying-to-create-table/#findComment-1065706 Share on other sites More sharing options...
Mchl Posted May 31, 2010 Share Posted May 31, 2010 The upper limit is 65536 TEXT is limited at 4GB Quote Link to comment https://forums.phpfreaks.com/topic/203093-error-with-mysql-syntax-trying-to-create-table/#findComment-1065708 Share on other sites More sharing options...
brem13 Posted May 31, 2010 Author Share Posted May 31, 2010 and thats better than text? i'm not expecting a 4gb message Quote Link to comment https://forums.phpfreaks.com/topic/203093-error-with-mysql-syntax-trying-to-create-table/#findComment-1065710 Share on other sites More sharing options...
Mchl Posted May 31, 2010 Share Posted May 31, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/203093-error-with-mysql-syntax-trying-to-create-table/#findComment-1065712 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.