Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Capture Radio Button Value

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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,
                                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']);


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

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

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

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


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

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

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

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

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

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

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

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

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


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

    $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;
New php-forum User
New php-forum User
Posts: 1
Joined: Sat Sep 15, 2012 1:58 am

Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.