Current location: Hot Scripts Forums » Programming Languages » PHP » You have an error in your SQL syntax. Help!


You have an error in your SQL syntax. Help!

Reply
  #1 (permalink)  
Old 08-31-04, 06:50 PM
SevEre SevEre is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
You have an error in your SQL syntax. Help!

This is the error im getting
Code:
gr_query() error with sql statement:INSERT INTO file_comments(fileid,username,comment) VALUES(,"Big-1","Everytime i try to post my comment i get this sql error!!!") mysql: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 '"Big-1","Everytime i try to post my comment i get this sql error
I think this is the string thats giving me trouble.
PHP Code:

gr_query('INSERT INTO file_comments fileid,username,comment VALUES('.$_POST['dib'].',"'.$_POST['username'].'","'.mysql_escape_string($_POST['comments']).'")'); 

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-31-04, 08:28 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi there,

Try this:

Code:
 gr_query('INSERT INTO file_comments fileid,username,comment VALUES("'.$_POST['dib'].'","'.$_POST['username'].'","'.mysql_escape_string($_POST['comments']).'")');
You got that error because you did not have any value in $_POST['dib'], creating a blank and breaking the syntax. I put double quotation marks around this variable, so even if this variable does not have a value, it will be treated as simply empty literal value. If this variable is supposed to hold a non-empty value all the time, there must be some mistakes made within your script.

HTH.
__________________
Blavv =|
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-31-04, 10:05 PM
SevEre SevEre is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by blaw
Hi there,

Try this:

Code:
 gr_query('INSERT INTO file_comments fileid,username,comment VALUES("'.$_POST['dib'].'","'.$_POST['username'].'","'.mysql_escape_string($_POST['comments']).'")');
You got that error because you did not have any value in $_POST['dib'], creating a blank and breaking the syntax. I put double quotation marks around this variable, so even if this variable does not have a value, it will be treated as simply empty literal value. If this variable is supposed to hold a non-empty value all the time, there must be some mistakes made within your script.

HTH.
Thanks but it didnt work either. This is very frustrating because i paid someone from these forums to add a comments script and a download counter to my original script. Well he didnt finish the job i paid him to do. So i keep getting errors. If someone can please help me out by taking a look at what i have i would be most appreciative.

Thanks in Advanced
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 09-01-04, 01:32 AM
SevEre SevEre is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Can anyone help fix these errors?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 09-01-04, 01:49 AM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hello again,

Are you getting the same error or a different one?

Try this then:

PHP Code:

gr_query("INSERT INTO file_comments (fileid, username, comment) VALUES ('".$_POST['dib']."', '".$_POST['username']."', '".mysql_escape_string($_POST['comments'])."')"); 

Good luck.
__________________
Blavv =|
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 09-01-04, 01:54 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
isint that supposed to do like this??

PHP Code:

gr_query('INSERT INTO file_comments (fileid, username, comment) VALUES("'.$_POST['dib'].'","'.$_POST['username'].'","'.mysql_escape_string($_POST['comments']).'")'); 

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 09-01-04, 04:02 AM
SevEre SevEre is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Both of those kinda worked. I stopped recieving the error and it said comment posted succesfully but the comment does not appear on the page. If anyone can help me via email or aim that would be so awesome. I found a few errors that i need help with so if anyone has the time please reply.

Thanks in advanced
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 09-08-04, 06:05 AM
SevEre SevEre is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Anyone help? The comment is being stored in the database but it is not showing on the page... Anyhelp? I get this error where the comment is supposed to show

Code:
gr_query() error with sql statement:SELECT posted,username,comment FROM file_comments WHERE fileid = mysql: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 '' at line 1
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Syntax Question Daemon ASP 2 03-29-04 02:55 PM
Need Help on error in SQL syntax eric1328 PHP 1 02-14-04 01:08 AM
Help with ASP & FORMS blessedrub ASP 0 01-23-04 11:22 AM
ERROR in SQL syntax near DATE_FORMAT() bitesize PHP 1 01-09-04 10:22 PM
change my field in this example sal21 ASP 3 07-14-03 03:49 AM


All times are GMT -5. The time now is 01:58 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.