Array ( [0] => Array ( [null] => 4125893692 ) [1] => Array ( [null] => 804902300 ) ) */ if(DEBUG) print_r($_POST); foreach($_POST as $spec => $votes){// ctgry, wght, gender if(!preg_match( '/(\d+)\_(\d+)\_(M|F|-1)$/', $spec, $fields) ) { continue; } $added_or_changed = 0; array_map('sqlite_escape_string', $fields); list( , $category_id, $weight, $gender) = $fields; foreach($votes as $n => $vote) { foreach($vote as $vote_id => $voted_for) { if($voted_for != 0) { $added_or_changed = 1; // only count one change for multiple votes per category+weight $query .= "DELETE FROM $votes_table WHERE voter_id = $voter_id and weight = $weight and category_id = $category_id and voted_for = $voted_for;"; $query .= "INSERT OR REPLACE INTO $votes_table VALUES($vote_id , $voter_id, $weight, $category_id, $voted_for);\n"; } } } $total += $added_or_changed; } $query .= "\nEND TRANSACTION;"; if(DEBUG) echo "query: $query"; $result = $dbh->exec($query); if(isset($_REQUEST['silent'])) die("$added_or_changed"); $s_votes = ($total == 1) ? "$total vote has" : "$total votes have"; if(!$result) { $headers = 'From: web@eschew.org' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $query .= "\n\nerror:" . print_r($dbh->errorInfo()); $query .= "\n\nPOST:\n" . print_r($_POST, TRUE); //echo "
$query"; mail('eschew@gmail.com', "[evotee] error" , $query, $headers); echo "Votes not recorded properly. Error logged and email sent."; exit; } ?>
For added security (to prevent vote tampering),
please close this window.
Thanks!