1. user votes on something, and they are the only voter
  2. user attempts to cancel their vote
  3. the site shows Drupal 7's trademark "The website encountered an unexpected error. Please try again later."

The error in the log is:

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 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 'WHERE entity_id=4254 AND delta=0' at line 1: UPDATE {field_revision_field_pollfield} SET field_pollfield_votes= WHERE entity_id=4254 AND delta=0; Array ( ) in pollfield_cancel_choice() (line 637 of path/to/drupal/sites/all/modules/pollfield/pollfield.module).

Notice that field_pollfield_votes gets no value after the equals sign. I believe that's because the $total_votes variable gets decremented to zero (from 1) and the variable is empty in PHP's eyes when it's converted to a string in the query sting generation. Lines 634-639:

	$query="UPDATE {".$table."} SET ".$field_votes."=".$total_votes." WHERE entity_id=".$vote->nid." AND delta=".$vote->field_name_delta;
  $query="UPDATE {".$table_data."} SET ".$field_votes."=".$total_votes." WHERE entity_id=".$vote->nid." AND delta=".$vote->field_name_delta;

Suggestion is to either:

  • convert all database queries to DBTNG OR
  • pass the variables into an associative array and still using db_query.
#2 pollfield.zip22.62 KBdinhquoc054
Members fund testing for the Drupal project. Drupal Association Learn more


sillygwailo’s picture

I could be wrong about whether it happens with just one vote, but it definitely happens. This happens for anonymous users more than anything.

dinhquoc054’s picture

22.62 KB

I fix error SQL and add function save poll_type. Fixed bug save cookie and ip in Anoynomus Alow.
Please file attachment.