Jump to content

Recommended Posts

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

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());

"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 :)

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.