Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-15-2008, 10:24 AM   PM User | #1
lpeek
Regular Coder

 
Join Date: May 2007
Posts: 130
Thanks: 9
Thanked 0 Times in 0 Posts
lpeek is an unknown quantity at this point
MySQL syntax error???

Hey Hey,

having quite a bit of trouble with some code.

Its all set up correctly, and should work, but i keep getting a syntax error.

heres the code in question:

PHP Code:
if ($cmd=="commentpost")
{

$SCREEN_ID $sid;
$MY_ID $_SESSION['user_id'];
$BODY $_POST['comment'];
$cur_date time();

$BODY addslashes(nl2br($BODY));

$sql mysql_query("INSERT INTO `screenshot_comments` (screen_id, user_id, timestamp, body, read) VALUES ('$SCREEN_ID','$MY_ID','$cur_date','$BODY','0')") or die(mysql_error());
                
$comment_posted true;

the error i get is:

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 'read) VALUES ('57','3','1210842919',abcde' at line 1

ive checked and double checked my database and all the columns are named correctly etc.

Any ideas?
lpeek is offline   Reply With Quote
Old 05-15-2008, 10:28 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
READ is mysql reserved keword, I think ,see http://dev.mysql.com/doc/refman/5.1/en/handler.html

So changing it like `read` may solve the issue. But usage of mysql keywords for naming tables/fields is not a good practice.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 05-15-2008, 10:33 AM   PM User | #3
lpeek
Regular Coder

 
Join Date: May 2007
Posts: 130
Thanks: 9
Thanked 0 Times in 0 Posts
lpeek is an unknown quantity at this point
Quote:
Originally Posted by abduraooft View Post
READ is mysql reserved keword, I think ,see http://dev.mysql.com/doc/refman/5.1/en/handler.html

So changing it like `read` may solve the issue. But usage of mysql keywords for naming tables/fields is not a good practice.
Ah ok then, ill change it and try again.

Confused me a bit because i already have 3 other tables with 'read' as one of the collumn and that gave me no errors.
lpeek is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:39 AM.


Advertisement
Log in to turn off these ads.