I created a simple content type with a pollfield and enabled it to anonymous users. I filled out one as anonymous and got this error message:

Error

The website encountered an unexpected error. Please try again later.

Error message

    Notice: Undefined variable: table in pollfield_save_vote_record() (line 607 of /home/par/www/d_7/sites/all/modules/pollfield/pollfield.module).
    PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined: INSERT INTO {pollfield_votes} (nid, field_table, field_name, uid, delta, hostname, field_name_delta, cookie) VALUES (:nid, :table, :field_name , :uid, :choice, :hostename, :delta, :cookie); Array ( [:nid] => 58 [:table] => [:field_name] => field_poll [:uid] => 0 [:choice] => 1 [hostname:] => 127.0.0.1 [:delta] => 0 [:cookie] => 0 ) in pollfield_save_vote_record() (line 608 of /home/par/www/d_7/sites/all/modules/pollfield/pollfield.module).

Comments

kappaluppa’s picture

I'm getting this error too. Any ideas on it? pollfield works perfectly for us, otherwise. Fixing this would allow us to use it.

Thanks!
K

kappaluppa’s picture

I am at beginner level with php, but I was mucking around with the module and I made some changes that will allow anon voters to vote without that error showing up (i have new error, but they can still vote).

Here are the changes I made to pollfield.module:
(although I don't know how to write patches yet, I'm trying to give the changes in 'patch style' (with layman comments following, lol) )

@@ -606  @@ function pollfield_save_vote_record($vote, $choice) {
  db_query("INSERT INTO {pollfield_votes} (nid, field_table, field_name, uid, delta, hostname, field_name_delta, cookie)
-      VALUES (:nid, :table, :field_name , :uid, :choice, :hostename, :delta, :cookie)",
+      VALUES (:nid, :table, :field_name , :uid, :choice, :hostname, :delta, :cookie)",

- array(':nid'=>$vote->nid, ':table'=>$table, ':field_name'=>$vote->field_name, ':uid'=>$vote->uid, ':choice'=>$choice,
-      'hostname:'=>$vote->hostname,':delta'=>$vote->field_name_delta, ':cookie'=>$vote->cookie));
+ array(':nid'=>$vote->nid, ':table'=>$vote->table, ':field_name'=>$vote->field_name, ':uid'=>$vote->uid, ':choice'=>$choice, ':hostname'=>$vote->hostname,':delta'=>$vote->field_name_delta, ':cookie'=>$vote->cookie));

  // Store IP or cookie if the user is anonymous
  else {
+    if ($vote->anonymous == 'anon_by_ip') {
  db_query("INSERT INTO {pollfield_votes} (nid, field_table, field_name, uid, delta, hostname, field_name_delta, cookie)
      VALUES (:nid, :table, :field_name , :uid, :choice, :hostname, :delta, :cookie)",
      array(':nid'=>$vote->nid, ':table'=>$vote->table, ':field_name'=>$vote->field_name, ':uid'=>$vote->uid, ':choice'=>$choice, ':hostname'=>$vote->hostname,':delta'=>$vote->field_name_delta, ':cookie'=>$vote->cookie));
+  }

+  if ($vote->anonymous == 'anon_by_cookie') {
    db_query("INSERT INTO {pollfield_votes} (nid, field_table, field_name, delta, hostname, field_name_delta, cookie)
      VALUES (%d, '%s', '%s', %d, '%s', %d, '%s')",
      $vote->nid, $vote->field_table, $vote->field_name,  $vote->choice, $vote->hostname, $vote->field_name_delta, $vote->cookie);
+     }

@@ - 638 @@ function pollfield_cancel_choice($vote) {

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

@@ - 638 @@ function pollfield_cancel_choice($vote) {

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

layman's explanation:

hostename should be hostname
':table'=>$table, should be ':table'=>$vote->table,
'hostname:'=>$vote->hostname, should be ':hostname'=>$vote->hostname,
$query on line 637 repeated
in the function pollfield_save_vote_record the ifs for IP & cookie were left out

I am getting this error, although the voting still happens

Strict warning: Creating default object from empty value in pollfield_vote() (line xxx of [...]\sites\all\modules\pollfield\pollfield.module).

kappaluppa’s picture

one other change i left out...

@@ - 899 @@function pollfield_user_votes($elements) {

    // user is anonymous
    else {
      if ($anonymous == 'anon_by_ip') {
        $result = db_query("SELECT delta FROM {pollfield_votes}
-          WHERE nid = :nid AND field_table=:field_table AND field_name=:field_name AND hostname = :hostname 'AND field_name_delta=:field_name_delta",
+          WHERE nid = :nid AND field_table=:field_table AND field_name=:field_name AND hostname = :hostname AND field_name_delta=:field_name_delta",

There is an extra apostrophe right before AND field_name_delta=:field_name_delta",

BigEd’s picture

I am getting the same error, as this fixed then?