brem13 Posted March 11, 2009 Share Posted March 11, 2009 hey, im trying to run a script that creates a table in a database. it gives me an error and i dont know why, the script is fine, i have another one thatis laid out the same way and that works fine. mysql_query("CREATE TABLE $username1( from VARCHAR(50), message TEXT, date VARCHAR(50), time VARCHAR(50), dt VARCHAR(50), dt2 VARCHAR(50))") or die(mysql_error()); error: 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 'from VARCHAR(50), message TEXT, date VARCHAR(50), time VARCHAR(50), dt VARCH' at line 2 Link to comment https://forums.phpfreaks.com/topic/148984-solved-mysql-table-create-error/ Share on other sites More sharing options...
wildteen88 Posted March 11, 2009 Share Posted March 11, 2009 from is a mysql reserved word. Wrap your field names in backticks and your query should run without errors. mysql_query("CREATE TABLE $username1( `from` VARCHAR(50), `message` TEXT, `date` VARCHAR(50), `time` VARCHAR(50), `dt` VARCHAR(50), `dt2` VARCHAR(50))") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/148984-solved-mysql-table-create-error/#findComment-782284 Share on other sites More sharing options...
samshel Posted March 11, 2009 Share Posted March 11, 2009 "from" is a keyword in MySQL. dont use it as a field. If u insist, try using it with backticks. but u will have to do this everytime you refer to that field. I prefer this.. mysql_query("CREATE TABLE $username1( message_from VARCHAR(50), message TEXT, date VARCHAR(50), time VARCHAR(50), dt VARCHAR(50), dt2 VARCHAR(50))") or die(mysql_error()); But this will also work. mysql_query("CREATE TABLE $username1( `from` VARCHAR(50), `message` TEXT, `date` VARCHAR(50), `time` VARCHAR(50), `dt` VARCHAR(50), `dt2` VARCHAR(50))") or die(mysql_error()); beaten by wildteen Link to comment https://forums.phpfreaks.com/topic/148984-solved-mysql-table-create-error/#findComment-782286 Share on other sites More sharing options...
brem13 Posted March 11, 2009 Author Share Posted March 11, 2009 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 ''from' VARCHAR(50), 'message' TEXT, 'date' VARCHAR(50), 'time' VARCHAR(50), ' at line 2 after the change, still giving error Link to comment https://forums.phpfreaks.com/topic/148984-solved-mysql-table-create-error/#findComment-782292 Share on other sites More sharing options...
wildteen88 Posted March 11, 2009 Share Posted March 11, 2009 No you're using quotes. You need to use backticks `field_name_here` Link to comment https://forums.phpfreaks.com/topic/148984-solved-mysql-table-create-error/#findComment-782295 Share on other sites More sharing options...
brem13 Posted March 11, 2009 Author Share Posted March 11, 2009 oh, lol, never heard of a backtick before, how do u type it?? is it the thing under the tilda ~ ? Link to comment https://forums.phpfreaks.com/topic/148984-solved-mysql-table-create-error/#findComment-782301 Share on other sites More sharing options...
wildteen88 Posted March 11, 2009 Share Posted March 11, 2009 For me (using a UK English keyword) its the key above the Tab and to left of the 1 key. Link to comment https://forums.phpfreaks.com/topic/148984-solved-mysql-table-create-error/#findComment-782303 Share on other sites More sharing options...
brem13 Posted March 11, 2009 Author Share Posted March 11, 2009 ok, thanks a lot bud, problem solved~!!! Link to comment https://forums.phpfreaks.com/topic/148984-solved-mysql-table-create-error/#findComment-782305 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.