$uid, 'cast' => "NOW()", 'comment' => "'" . DBEscape(stripslashes($_POST['comment'])) . "'" ); foreach($fields as $key) { $pkey = strval($_POST[$key]); $data[$key] = strlen($pkey) ? intval($pkey) : "NULL"; } if (Query("SELECT * FROM wm_survey WHERE uid=$uid")) { // already voted -> UPDATE the vote unset($data['uid']); $q = ""; foreach($data as $key => $value) { $q .= ", $key=$value"; } Query("UPDATE wm_survey SET " . substr($q, 2) . " WHERE uid=$uid"); } else { // not voted yet -> INSERT a new vote $keys = implode(", ", array_keys($data)); $values = implode(", ", array_values($data)); Query("INSERT INTO wm_survey($keys) VALUES ($values)"); } redirect("survey.php"); CloseDB(); ?>