Title: SQL syntax error
Last modified: August 21, 2016

---

# SQL syntax error

 *  Resolved [pawelo](https://wordpress.org/support/users/pawelo/)
 * (@pawelo)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/sql-syntax-error-7/)
 * After install the NextGEN gallery voting plugin i get SQL syntax error on my 
   page:
 * WordPress 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‘)
   AND criteria_id = ‘0’ AND ip = ‘xx.xx.xxx.xx’ ORDER BY dateadded DESC’ at line
   1]
    SELECT * FROM wp_nggv_votes WHERE pid IN () AND criteria_id = ‘0’ AND ip 
   = ‘xx.xx.xxx.xx’ ORDER BY dateadded DESC
 * I also have checked “Only allow 1 vote per person for this gallery” in gallery
   settings. For “Only allow 1 vote per person for this image” everything seems 
   to be ok.
 * It seems like the function $picturelist = nggdb::get_gallery($image->gid); always
   return empty array in ngg-voting.php file.
 * Anybody knows this issue?
 * [https://wordpress.org/plugins/nextgen-gallery-voting/](https://wordpress.org/plugins/nextgen-gallery-voting/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [shauno](https://wordpress.org/support/users/shauno/)
 * (@shauno)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/sql-syntax-error-7/#post-4696418)
 * Hi pawelo
 * Do you have images in the gallery at all? I haven’t seen this issue before, but
   NGG keep updating big things their side that are breaking the voting plugin. 
   I will try have a look when I get a chance.
 * Thanks for the report
 *  Thread Starter [pawelo](https://wordpress.org/support/users/pawelo/)
 * (@pawelo)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/sql-syntax-error-7/#post-4696421)
 * yes, I have gallery and three images inside. Images are displaying in page and
   also the stars or hands icons too, but checking if IP already voted is broken
   also ajax request not working after click on voting icon.
 * clicked image “$image->gid” is correct, and then I need to get all images from
   gallery which have this ID. the nggdb::get_gallery($image->gid); is not working
   correct, is there any other method to get the images objects fromt the gallery?
 *  Thread Starter [pawelo](https://wordpress.org/support/users/pawelo/)
 * (@pawelo)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/sql-syntax-error-7/#post-4696492)
 * i already figured it out. thanks!
 *  Plugin Author [shauno](https://wordpress.org/support/users/shauno/)
 * (@shauno)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/sql-syntax-error-7/#post-4696494)
 * What was the problem? As I said, I had never seen it before, and I haven’t had
   a chance to try replicate it.
 *  Thread Starter [pawelo](https://wordpress.org/support/users/pawelo/)
 * (@pawelo)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/sql-syntax-error-7/#post-4696495)
 * Like I said for some reason the: $picturelist = nggdb::get_gallery($image->gid);
   in functions:
 * ipHasVotedOnGalleryImage(),
    userHasVotedOnGalleryImage()
 * was returning empty array(), so:
 *  WHERE pid IN (“.implode(‘, ‘, $inPid).”)
 * generate SQL syntax error.
 * Because I don’t known code of your plugin, I go around with the images IDs.
 * I get the IDs from NextGen gallery plugin, just before displaing images from 
   gallery ( adding a second loop ), something like:
 *  <?php $imagesIds = array(); ?>
    <?php for ($i=0; $i<count($images); $i++){ $
   image = $images[$i]; $imagesIds[] = esc_attr($image->{$image->id_field}); } ?
   >
 * and then pass the ids throu the, voting form initializer:
 * <?php echo nggv_imageVoteForm($image->pid, 0, $imagesIds); ?>
 * then in voting plugin I added:
 * if(empty($inPid))
    $inPid = $imagesIds
 * And now it works. But it’s a way around, you probably fix it better.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘SQL syntax error’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/nextgen-gallery-voting.svg)
 * [NextGEN Gallery Voting](https://wordpress.org/plugins/nextgen-gallery-voting/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/nextgen-gallery-voting/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/nextgen-gallery-voting/)
 * [Active Topics](https://wordpress.org/support/plugin/nextgen-gallery-voting/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/nextgen-gallery-voting/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/nextgen-gallery-voting/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [pawelo](https://wordpress.org/support/users/pawelo/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/sql-syntax-error-7/#post-4696495)
 * Status: resolved