Capture Radio Button Value

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Caine
New php-forum User
New php-forum User
Posts: 1
Joined: Sat Sep 15, 2012 1:58 am

Capture Radio Button Value

Postby Caine » Sat Sep 15, 2012 2:19 am

Hi everybody....I have 4 radio button on php form. This is listed below in my code.
The questions are being retrieved from mysql using:

Code: Select all

   
//query for question and corresponding answers
           $Rs = mysql_query("SELECT question.Question,
                                      answer.Answer1,
                                      answer.Answer2,
                                      answer.Answer3,
                                      answer.Answer4,
                                      question.QuestionID
                                FROM  question , answer
                                WHERE question.QuestionID = answer.AnswerID
                                AND question.ThemeID =$ThemeID  limit $x, 1 ");
                               
      
        //fetch the result
        while($rows= mysql_fetch_array($Rs)){
           
            //get total number of question to display
            //for this theme id.
            //save total number in variable $total_quest
            $result = mysql_query(" SELECT count(question) AS mycount
                                    FROM question
                                    WHERE question.ThemeID = $ThemeID ") ;
                                   
            $row = mysql_num_rows($result);
           
            while($row = mysql_fetch_array($result))
            {
             
              $total_quest =  ($row['mycount']);
             
            }
 



PHP FORM FOR MY QUESTIONS AND ANSWERS


Code: Select all

<form action="quizz.php" method="post" >
   
      <table border="1" style="margin-left: 90px;">

      <tr>
         <td id="ques" colspan="2" width="520" height="50">
           
            <?php echo $rows['Question'];?></td>

      </tr>
 
      <tr>
         <td id="answer1" width="450" height="50">

                <?php echo $rows['Answer1'];?>

            </td>



         <td id="result1" width="70" height="50">
            <label>
         
               <input type="radio" id="ans1" class="rbnNumber" value="1" name="rbnPosition"/>       
            
             
            </label> 
            </td>
      </tr>
 
      <tr>
         <td id="answer2" width="450" height="50">

                <?php echo $rows['Answer2'];?></td>

         <td id="result2" width="70" height="50">
            <label>
         
             <input type="radio" id="ans2" class="rbnNumber" value="2" name="rbnPosition"/>
         
            </label> 
            </td>
      </tr> 
 
      <tr>
         <td id="answer3" width="450" height="50">

                <?php echo $rows['Answer3'];?></td>

         <td id="result3" width="70" height="50">
            <label>
         
            <input type="radio" id="ans3" class="rbnNumber" value="3" name="rbnPosition"/>
         
            </label> 
            </td>
      </tr> 
 
      <tr>
         <td id="answer4" width="450" height="50">

                <?php echo $rows['Answer4'];?></td>

         <td id="result4" width="70" height="50">
            <label>
           
         <input type="radio" id="ans4" class="rbnNumber" value="4" name="rbnPosition"/>
         
            </label>
            </td>
   </tr>





I have a link as : echo '<a href="mainquiz.php?nextquestion=<?php echo '.$x.'+1;?>">

<img src="images/suiv.jpg" />

</a>';


Now i want to get the value for each question.
That is, i have another php page to do the processing. Quizz.php
I want to know for each question what the user has seleced.
i have tried with this code below but i am getting the answer for only one question.

Code: Select all

<?php
session_start();

    $q1_ans_pos = $_POST['rbnPosition'];
    $quest_number = $_SESSION['quest'];
    $total_quest = $_SESSION['total_quest'];
    $x = $_SESSION['x'];

 echo "Question: $quest_number <br/>";   
 echo "Answer: $q1_ans_pos <br/>";

 echo "Total Number of question: $total_quest <br/>";
 echo $x;
?>

Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron