session - PHP Multipage survey - moving to the next part -


i'm creating survey based on list of multiple choice questions, user clicks button on each page transition next question.

the set have now, each question individual form, each each choice being submit button containing value of answer. problem set user has click answer twice (or refresh page) move on next part of survey. understand why happening know has reloaded run php again check if $_session set.

i'm sure how should modify around problem.

if (!isset($_session['part1'])) {           $survey_question = "surveyquestions , answers here";          if (isset($_post['part1'])) {              $_session['part1'] = $_post['part1'];          } } else if (!isset($_session['part2'])) {           $survery_question = "next questions , answers form";  ... }  echo $survey_question; 

i added onclick event each submit button have page reloaded via javascript no avail.

from understanding, add hidden value in question form indicates question answered.

... <input type="hidden" name="questionnum" value="1" /> ... 

then inside php file, grab value , use display next question.

$question_num = (isset($_post['questionnum'])) ? (int)$_post['questionnum'] : 0;  switch($question_num) {     case 0:         $survey_question = "question 1.";         break;     case 1:         if(isset($_post['part1'])) {             $_session['part1'] = $_post['part1'];         }          $survey_question = "question 2.";         break;      case 2:         ... } 

when user firsts go php page, question number set 0 , display first question. when submit page again, questionnum post variable set 1 , save first answer in session , print out second question.