I am having trouble with the $updatequery SQL, this php script accepts 3 post variables in an ajax call, the first is an array of previously correct answers and not relevant here. $win is 0 or 1 depending on whether the previous question was answered correctly or not and $id is the primary id of the word (it's a word match game, like Korean flashcards). $updatequery is intended to build up statistics for each word, how many people get it right and determine how difficult the word is simply by recording how many times it has been clicked and how many of those times it was answered correctly. If I answer the word wrong it is reflected accurately in the database: 1 click, no wins. However is I answer correctly it says 0 clicks, no wins in the database...what is going wrong?!?!?!
<?php
$dbcon = mysql_connect("localhost", "tulesblo_tules", "Gromit554?") or die(mysql_error());
mysql_select_db("tulesblo_koreangame", $dbcon) or die(mysql_error());
mysql_query("SET NAMES utf8");
$correctarray = explode(",", $_POST["correct"]);
$win = (int)$_POST["win"];
$id = (int)$_POST["id"];
$correct = "";
$y = 1;
if ($id > 0) {
$updatequery = "UPDATE words SET clicks=clicks+1 AND wins=wins+ '$win' WHERE id= '$id'";
mysql_query($updatequery) or die(mysql_error());
}
foreach($correctarray as $x){
$correct .= " id != " . $x;
if ($y == count($correctarray)) {break;}
$correct .= " AND"; $y++;
}
//pick 4 random pairs
$filter = count($correctarray) > 1?"WHERE" . $correct:"";
$querystring = "SELECT * FROM words ".$filter." ORDER BY RAND() LIMIT 4";
$query = mysql_query($querystring);
//turn them into multiarray
$x = 0;
$multiarray = array();
while ($result = mysql_fetch_assoc($query)){
$multiarray[$x] = array(
"id" => $result['id'],
"korean" => $result['korean'],
"english" => $result['english']
);
$x++;
}
array_push ($multiarray,$win,$id);
//send as JSON to client
//array_push($multiarray, $querystring, count($correctarray));
echo json_encode($multiarray);
?>