Advertisement:

Author Topic: Database Error: You have an error in your sql syntax  (Read 2969 times)

Offline mcmedal001

  • Semi-Newbie
  • *
  • Posts: 90
  • Gender: Male
  • www.cynamix.net
    • The Ultimate Worldwide Forum
Database Error: You have an error in your sql syntax
« on: February 11, 2010, 09:58:03 AM »
This was what i saw in my forum error log 2day. Database 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 " at line 3
File: /home/cynamix/public_html/Unaabjoint.net/Sources/Poll.php
Line: 178

plz what im i to do?. IS THIS A FATAL ERROR?.

Offline Paul_Pauline

  • In Memorium - Paul & Pauline
  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,788
  • Gender: Male
Re: Database Error: You have an error in your sql syntax
« Reply #1 on: February 11, 2010, 10:11:10 AM »
Hi.

It's not something I can help you with, but if you attach a copy of that file here i'm sure someone will be able to help you   ;)
"In every life, no matter how full or empty one's purse, there is tragedy. It is the one promise life always fulfills.
Happiness is a gift and the trick is not to expect it, but to delight in it when it comes and to add to other people's store of it."
Pauline was one of those rare people who increased the store of happiness in the world.

MrPhil

  • Guest
Re: Database Error: You have an error in your sql syntax
« Reply #2 on: February 11, 2010, 11:26:47 AM »
Was the complete SQL statement given as part of the error message? That would be quite useful to have. What SMF version, and what mods are installed?

If this is the section of code, and the query at fault:
Code: [Select]
$setString .= "
($row[ID_POLL], $ID_MEMBER, $id),";
}
$setString = substr($setString, 0, -1);

// Add their vote to the tally.
db_query("
INSERT IGNORE INTO {$db_prefix}log_polls
(ID_POLL, ID_MEMBER, ID_CHOICE)
VALUES $setString", __FILE__, __LINE__);

my guess is that $row[ID_POLL] and/or $ID_MEMBER and/or $id are missing a value for some reason, leaving an empty value field. That would be a bug in SMF (or any mod affecting this section) that it didn't check for undefined values. The substr call should just trim off the last trailing "," in a multi-VALUES string.

Offline mcmedal001

  • Semi-Newbie
  • *
  • Posts: 90
  • Gender: Male
  • www.cynamix.net
    • The Ultimate Worldwide Forum
Re: Database Error: You have an error in your sql syntax
« Reply #3 on: February 11, 2010, 02:59:15 PM »
Plz what should i attach to this post? MySQL or what?. And i dont use any mode on my site,  no mod at all.. But please what should i attach to here, and im using babylon theme.

MrPhil

  • Guest
Re: Database Error: You have an error in your sql syntax
« Reply #4 on: February 11, 2010, 04:06:59 PM »
Did you get as part of your error message something like
Code: [Select]
INSERT IGNORE INTO smf_log_polls
         (ID_POLL, ID_MEMBER, ID_CHOICE)
      VALUES (, 1375, 208)
If so, we need to see it here. The example I gave has an error in it. Given the line number you gave in your first post, that's the most likely SQL query to give an error. And again, what SMF version?

Offline mcmedal001

  • Semi-Newbie
  • *
  • Posts: 90
  • Gender: Male
  • www.cynamix.net
    • The Ultimate Worldwide Forum
Re: Database Error: You have an error in your sql syntax
« Reply #5 on: February 11, 2010, 08:10:44 PM »
This is what i latter saw in my error log, i didnt see any error like the one u posted, what i latter see is what i put below.


Invalid arguement
supplied for foreach()
File: /home/cynamix/public_html/Unaabjoint.net/Sources/poll.php
Line: 164


Im using Smf 1.1.10.  IS THIS A FATAL ERROR?

MrPhil

  • Guest
Re: Database Error: You have an error in your sql syntax
« Reply #6 on: February 11, 2010, 08:35:41 PM »
That's just a little "upstream" of the first error you reported.
Code: [Select]
foreach ($_REQUEST['options'] as $id)
{
$id = (int) $id;

$pollOptions[] = $id;
$setString .= "
($row[ID_POLL], $ID_MEMBER, $id),";
}
$setString = substr($setString, 0, -1);

// Add their vote to the tally.
db_query("
INSERT IGNORE INTO {$db_prefix}log_polls
(ID_POLL, ID_MEMBER, ID_CHOICE)
VALUES $setString", __FILE__, __LINE__);

Line 164 is the first ("foreach" statement). Certainly if the "foreach" statement is blowing up (because $_REQUEST['options'] is not an array), that will create a bad $setString (if it even gets that far). These may be two separate errors -- you got an SQL error before, and now you're getting a foreach error in the PHP? Or are you getting both?

Offline mcmedal001

  • Semi-Newbie
  • *
  • Posts: 90
  • Gender: Male
  • www.cynamix.net
    • The Ultimate Worldwide Forum
Re: Database Error: You have an error in your sql syntax
« Reply #7 on: February 12, 2010, 11:36:17 AM »
What should i do now? Is this a very  big problem? How do we solve the problem now?

MrPhil

  • Guest
Re: Database Error: You have an error in your sql syntax
« Reply #8 on: February 12, 2010, 12:15:56 PM »
You could start by answering the questions. Are you only getting the "foreach" error, or are you also getting the SQL syntax error? You must have something changed in your code, that there is no "options" array in GET or POST (no one else reports this problem). Perhaps you've been hacked? You should upgrade to 1.1.11. As you have no mods, it should be a painless process. See if your problem goes away then. If not, we can continue working on it.

Offline mcmedal001

  • Semi-Newbie
  • *
  • Posts: 90
  • Gender: Male
  • www.cynamix.net
    • The Ultimate Worldwide Forum
Re: Database Error: You have an error in your sql syntax
« Reply #9 on: February 12, 2010, 01:38:21 PM »
Its not showing thd error again does dat means that the error has been corrected?.

MrPhil

  • Guest
Re: Database Error: You have an error in your sql syntax
« Reply #10 on: February 12, 2010, 06:53:22 PM »
It depends on what caused the error in the first place...

If you're doing exactly the same actions as before, and no errors are generated, maybe you're in luck. If somehow the error has been corrected, without any action on your part, the only legitimate way would be if your hosting service fixed something, or restored some files. You might ask your host. On the other hand, if a hacker "fixed" their code because it's causing problems (i.e., is noticeable), that means you still have problems.

Offline mcmedal001

  • Semi-Newbie
  • *
  • Posts: 90
  • Gender: Male
  • www.cynamix.net
    • The Ultimate Worldwide Forum
Re: Database Error: You have an error in your sql syntax
« Reply #11 on: February 13, 2010, 01:38:40 AM »
The error started from a Poll, the poll has been lockd. but my site is working fine, my host didnt do anything.

Offline JimM

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,977
  • Gender: Male
    • Southern Spirit Hunters
Re: Database Error: You have an error in your sql syntax
« Reply #12 on: March 14, 2010, 04:31:08 PM »
If this is solved, please mark it solved by clicking the Mark Topic Solved link at the bottom left.
Jim "JimM" Moore
Former Support Specialist
jimm@simplemachines.org

Please do not PM me for support!                   
Installing SMF
Upgrade SMF
Manual Installation of Mods