0
<?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>

Edited by JorgeM: fix formatting

4
Contributors
3
Replies
25
Views
3 Years
Discussion Span
Last Post by mchourishi
0

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

0

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 />";

Edited by diafol: indent code blocks

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.