<?php

$count;

session_start();
print_r($_SESSION);
$myarray=array();
$myarray=@$_SESSION['myarray'];
$myarray=array();
$myarray=@$_SESSION['myarray'];

$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="candidates"; // Database name 
$tbl_name="qbank"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");


if($_POST['next']=="next")
{   
    if(@$_SESSION['count']<=10)  
    {   
      echo @$_SESSION['count'];
      $myarray=array();
      $myarray=@$_SESSION['myarray'];
      echo "    ---------   ";
      $myid=$myarray[@$_SESSION['count']-1];
      $query=mysql_query("SELECT * FROM  qbank WHERE qbank.qid=$myid");
      if($query)
      {

         while($row = mysql_fetch_assoc($query))
         {
            echo("<pre>");
            echo"</br>";
            echo $row['qtext']; echo"</br>";
            $value1=$row['choiceA'];
            print "<input type='radio' name='choiceA' value='$value1'>".$value1."</input><br />";
            $value2=$row['choiceB'];
            print "<input type='radio' name='choiceA' value='$value2'>".$value2."</input><br />";
            $value3=$row['choiceC'];
            print "<input type='radio' name='choiceC' value='$value3'>".$value3."</input><br />";
            $value4=$row['choiceD'];
            print "<input type='radio' name='choiceD' value='$value4'>".$value4."</input><br />";
            echo("<pre>");
        }

      }
    }
    else
    {
    echo "Reach final"; 
    }
    $count=@$_SESSION['count'];
    $count++;
    $_SESSION['count']=$count;      
}
if($_POST['next']=="skip")
{

}
?>

<form name="form1" method="post" action="questionpaper.php">

<input name="next" type="submit" value="next" />
<input name="next" type="submit" value="skip" />
</form>

Recommended Answers

What difficulty are you having? All you did was post code without an explanation of the problem.

Jump to Post

All 3 Replies

What difficulty are you having? All you did was post code without an explanation of the problem.

If you want multiple radio buttons to work together (user can only select one at a time) then you have to give all of them the same name like so:

 print "<input type='radio' name='Choices' value='$value1'>".$value1."</input><br />";
$value2=$row['choiceB'];
print "<input type='radio' name='Choices' value='$value2'>".$value2."</input><br />";
$value3=$row['choiceC'];
print "<input type='radio' name='Choices' value='$value3'>".$value3."</input><br />";
$value4=$row['choiceD'];
print "<input type='radio' name='Choices' value='$value4'>".$value4."</input><br />";

A group of radio buttons should have same name to work properly.
However the values will differ.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.