php - How to check which radio button a user checked if not in a form -


i have textfile information using create quiz. displaying 1 quiz question @ time however. generating radio buttons based on number of questions , have submit button after loop generates radio buttons. can't figure out how radio button user selected in $_post array when click submit. initial thought use form tag , have loop run don't know if works or how make work syntactically.

textfile (the last number index of right answer):

what charmander evolve to?#charmeleon:charizard:squirtle#0 main character in pokemon?#misty:ash:obama#1 

script:

<?php          $indextemp = intval($_session["index"]);          if($_session["numquestions"] == $indextemp){             echo "your results are: ";             echo "<form action=\"process.php\" method=\"post\"> main screen: <input type=\"submit\"><br \> </form>";             exit();         }          $filename = $_session["quizoftheday"];          $quizstuff = file($filename);         $ctr =1;           $questioninfo = $quizstuff[$indextemp];          $questionparse = explode("#", $questioninfo);         $_session["correctans"] = $questionparse[2];         echo $_session["correctans"]." line 55 <br />";         $answerchoices = explode(":",$questionparse[1]);          echo "$questionparse[0] ? <br />";         #this radio buttons being generated         foreach ($answerchoices $answerchoice) {                 echo "<input type='radio' name='ans$ctr' id='q1' value='$ctr'> <label for='q1'> $answerchoice </label> <br />";                 $ctr +=1;             }         $_session["index"] = $indextemp +1;         echo "<form action=\"questions.php\" method=\"post\"> <input type=\"submit\"><br \> </form>";       ?> 

obtaining data radio buttons , checkboxes can little tricky, due lack of understanding of how radio buttons , checkboxes work.

it important remember 2 facts:

  1. checkbox "names" must unique each checkbox
  2. radio button "names" must identical each group of buttons

enter image description here

update foreach since must have same name radio buttons different values.

<?php foreach ($answerchoices $answerchoice) { echo "<input type='radio' name='ans' id='q1' value=".$ctr."> <label for='q1'>".$answerchoice."</label> <br />"; $ctr +=1; } ?> 

now for-each concatenation looks wrong , have updated , since concatenation wrong value not displayed in radio button. radio button value count of increment variable.


Comments

Popular posts from this blog

php - isset function not working properly -

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -