PHP: Cookie read incorrectly or fault in logic? -


i trying make "simple" guessing game in php. however, seems when user presses "submit" button submit answer, @ (seemingly random) moments, in stead of seeing question again , seeing correct answer, different question , answer displayed. i've got feeling issue in logic or maybe cookie stores question number. here's snip:

if (isset($_post['q'])) {     $questionno = $_post['q'];     $text = str_replace("\\", "", $_post['ans']);     $text = ltrim(rtrim($text, "'"), "'");     $button = "next one";     $action = "window.location='game.php';";     $verify = true; } else {     $verify = false;     $answered = unserialize(urldecode($_cookie['answered']));     if (gettype($answered) == 'boolean') {         $answered[0] = "";     }      while (true) {         if (array_search($questionno, $answered) > 0 && count($answered) < ($numberofquestions + 1)) {         $questionno = $questionno + 1;         $questionno = ($questionno > $numberofquestions ? $questionno - $numberofquestions : $questionno);     } else {         $answered[count($answered)] = $questionno;         setcookie('answered', urlencode(serialize($answered)));         break;     } } 

the longer code i've put pastebin, available here. i've in case pasted sql data, which here.

thanks ahead ideas!


Comments