Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old January 20th, 2004, 10:00 PM
DorkRawk DorkRawk is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 173 DorkRawk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to DorkRawk
SQL syntax error

I am trying to use a prewritten function that submits to a database. (if it helps it is the private message service that this forum uses) Anyways, I'm useing a send_message() function that submits and entry to the database and Im getting this 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 '(mto,subject,message,mfrom) values(test1,Band confirmed,test1 -

I'm not sure what's causeing the syntax error, any ideas?

Reply With Quote
  #2  
Old January 20th, 2004, 10:20 PM
sliver's Avatar
sliver sliver is offline
Moderator
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: WI, USA
Posts: 903 sliver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 54 m 35 sec
Reputation Power: 2
Send a message via AIM to sliver Send a message via XFire to sliver
RE: SQL syntax error

Can we see the whole query please?

Reply With Quote
  #3  
Old January 21st, 2004, 12:41 AM
DorkRawk DorkRawk is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 173 DorkRawk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to DorkRawk
RE: SQL syntax error


php Code:
Original - php Code
  1.  
  2. $to=$member;
  3. $subj="Band confirmed";   $message="$member - You have just been confirmed as a bandmember of $bandname .You now have full access to edit the band's information.  Enjoy.  - MidwestSka.com";
  4. $from = "MidwestSka.org";

php Code:
Original - php Code
  1.  
  2.  
  3. $columns = "mto,subject,message,mfrom";
  4.             $values = "$to,$subj,$message,$from";
  5.        
  6.             if(db_insert($config[pmtable],$columns,$values))
  7.  

php Code:
Original - php Code
  1.  
  2. function db_insert($table,$columns,$values)
  3. {
  4.     global $config,$lastid,$sqlCount;
  5.     $sqlCount++;
  6.     //LogQuery("[".date("H:i:s")."] SQL Insert: Table: $table ($columns) ($values)");
  7.     if (mysql_db_query($config[dbname],"INSERT INTO $table ($columns) values($values)")or die(mysql_error()))
  8.     {
  9.         $lastid = mysql_insert_id();
  10.         return TRUE;
  11.     }
  12.     else
  13.         return FALSE;
  14. }

Reply With Quote
  #4  
Old January 21st, 2004, 01:22 AM
nawlej nawlej is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Dallas, Tx. USA
Posts: 2,008 nawlej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 7 m 51 sec
Reputation Power: 4
RE: SQL syntax error

What happens when you echo the query to the screen?

Reply With Quote
  #5  
Old January 21st, 2004, 02:59 AM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 3
Send a message via Yahoo to nazly
RE: SQL syntax error

Try modyfying the SQL string in the function...

php Code:
Original - php Code
  1.  
  2. function db_insert($table,$columns,$values)
  3. {
  4.     .
  5.     .
  6.     .
  7.     if (mysql_db_query($config[dbname],"INSERT INTO $table ($columns) values ($values)")or die(mysql_error()))
  8.     .
  9.     .
  10.     .
  11. }


If you look at it closely there was a space missing after 'values'

Reply With Quote
  #6  
Old January 21st, 2004, 03:08 AM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 3
Send a message via Yahoo to nazly
RE: SQL syntax error

The above was just a suggestion for you to try out though might not solve your problem..

Quote:
What happens when you echo the query to the screen?


Did u consider doing this??
To do this just add this line to the function..

php Code:
Original - php Code
  1.  
  2. function db_insert($table,$columns,$values)
  3. {
  4.     global $config,$lastid,$sqlCount;
  5.     $sqlCount++;
  6.     //LogQuery("[".date("H:i:s")."] SQL Insert: Table: $table ($columns) ($values)");
  7.     echo "INSERT INTO $table ($columns) values ($values)";
  8.     if (mysql_db_query($config[dbname],"INSERT INTO $table ($columns) values($values)")or die(mysql_error()))
  9.     {
  10.         $lastid = mysql_insert_id();
  11.         return TRUE;
  12.     }
  13.     else
  14.         return FALSE;
  15. }

Reply With Quote
  #7  
Old January 21st, 2004, 06:34 AM
DorkRawk DorkRawk is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 173 DorkRawk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to DorkRawk
RE: SQL syntax error

The output from
echo "INSERT INTO $table ($columns) values ($values)";
is

INSERT INTO (mto,subject,message,mfrom) values ('test1','Band confirmed','test1 - You have just been confirmed as a bandmember of Test Band Two . You now have full access to edit the band's information. Enjoy. - MidwestSka.com','MidwestSka.org')

Everything seems to be in order there, I think...

Reply With Quote
  #8  
Old January 21st, 2004, 08:31 AM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 3
Send a message via Yahoo to nazly
RE: SQL syntax error

Quote:
Everything seems to be in order there, I think...

Yep.. Everything seems to be ok except that the field value that you are trying to insert seem to be generating the error..

$message contains a string that has a single quote in it.. To solve this you can use addslashes() function. Or by adding back slashes manually..

php Code:
Original - php Code
  1.  
  2. $message="$member - You have just been confirmed as a bandmember of $bandname .You now have full access to edit the band's information.  Enjoy.  - MidwestSka.com";
  3. $message=addslashes($message);

Reply With Quote
  #9  
Old January 21st, 2004, 08:19 PM
-vertigo- -vertigo- is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Louth, Lincolnshire
Posts: 314 -vertigo- User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 24 sec
Reputation Power: 2
RE: SQL syntax error

Quote:
The output from
echo "INSERT INTO $table ($columns) values ($values)";
is

INSERT INTO (mto,subject,message,mfrom) values ('test1','Band confirmed','test1 - You have just been confirmed as a bandmember of Test Band Two . You now have full access to edit the band's information. Enjoy. - MidwestSka.com','MidwestSka.org')


I don't see no table name...

Reply With Quote
  #10  
Old January 22nd, 2004, 12:28 AM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
RE: SQL syntax error

Maybe this is where you went wrong. Did you forget to use single quotes in $config array around the element name? That will cause not to pass the value of tablename to your db_insert() function.
I mean do like this:
php Code:
Original - php Code
  1. if(db_insert($config['pmtable'],$columns,$values))
instead of...
php Code:
Original - php Code
  1. if(db_insert($config[pmtable],$columns,$values))

Reply With Quote
  #11  
Old January 29th, 2004, 03:00 PM
fdocruzs fdocruzs is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Ontario, Canada
Posts: 18 fdocruzs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to fdocruzs
RE: SQL syntax error

I don't know if this was solved but I think that the problem is on the Insert statement:

INSERT INTO (mto,subject,message,mfrom) values ('test1','Band confirmed','test1 - You have just been confirmed as a bandmember of Test Band Two . You now have full access to edit the band's information. Enjoy. - MidwestSka.com','MidwestSka.org')

Notice that single quotes are ok excepto that you have a "band's" in the middles and when you run that SQL the is like the string finish on the word "band". Try to replace the "band's" word with something similar "band`s".

Reply With Quote
  #12  
Old January 29th, 2004, 03:10 PM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4