Passing radio buton variable to check.php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
razel8604
Forum Newbie
Posts: 8
Joined: Mon May 26, 2008 4:41 am

Passing radio buton variable to check.php

Post by razel8604 »

hello..can somebody help me? i have a 3 pages exam, and when i checked my exam, it only check the last page not included the 1st and the 2nd...

page1.php
------------

<?php
session_start();
include ('../contentdb.php');

$q1 = $_GET["$q"];
$_SESSION[$q1] = $_GET['$q'];

$type = $_GET["type"];
$display = mysql_query("SELECT * FROM quiz where category = '$type' ORDER BY qnumber ASC LIMIT 0,10");

if (!$submit) {

echo "<tr><td>";
echo "<form method=post action=page2.php name=myform>";
while ($row = mysql_fetch_array($display)) {

$qnumber = $row["qnumber"];
$id = $row["id"];
$question = $row["question"];
$opt1 = $row["opt1"];
$opt2 = $row["opt2"];
$opt3 = $row["opt3"];
$answer = $row["answer"];
$q = $row["q"];

echo "<tr><td>";
echo "<tr><td colspan=10 align=left><b>$qnumber. $question</b></td></tr>";
echo "<tr><td colspan=10 align=left><input type=radio name=\"$q\" value=\"$opt1\">$opt1</td></tr>
<tr><td colspan=10 align=left><input type=radio name=\"$q\" value=\"$opt2\">$opt2</td></tr>
<tr><td colspan=10 align=left><input type=radio name=\"$q\" value=\"$opt3\">$opt3</td></tr>";
echo "<tr><td><br></td></tr>";
}


echo "<tr><td><input type='hidden' name='formVar' value=''></td></tr>";
echo "<tr><td><input type='submit' value='Next Page' name='submit'></td></tr>";
echo "</form>";

}
?>
=========================================================
page2.php
-----------
<?php
session_start();
include ('../contentdb.php');
include ('../header.php');

$q2 = $_GET["$q"];
$_SESSION[$q2] = $_GET['$q'];

$_SESSION[$q1];
$_SESSION[$type];

$display = mysql_query("SELECT * FROM quiz where category ='$type' ORDER BY qnumber ASC LIMIT 10,10");

$myvar = $_POST['formVar'];
echo "<tr><td>$myvar</td></tr>";

echo $_Session[$name];

if ($submit) {

echo "<tr><td>";

while ($row = mysql_fetch_array($display)) {

$qnumber = $row["qnumber"];
$id = $row["id"];
$question = $row["question"];
$opt1 = $row["opt1"];
$opt2 = $row["opt2"];
$opt3 = $row["opt3"];
$answer = $row["answer"];
$q = $row["q"];

echo "<tr><td>";
echo "<tr><td colspan=10 align=left><b>$qnumber. $question</b></td></tr>";
echo "<tr><td><input type='hidden' name=\"q$id\" value=''></td></tr>";
echo "<tr><td colspan=10 align=left><input type=radio name=\"q$id\" value=\"$opt1\">$opt1</td></tr>
<tr><td colspan=10 align=left><input type=radio name=\"q$id\" value=\"$opt2\">$opt2</td></tr>
<tr><td colspan=10 align=left><input type=radio name=\"q$id\" value=\"$opt3\">$opt3</td></tr>";
echo "<tr><td><br></td></tr>";
}

echo "<tr><td><input type='button' value='Previous' onClick=javascript:history.back()>";
echo "<form method=post action=page3.php name=myform>";
echo "<td><input type='hidden' name='formVar' value=''></td>";
echo "<td><input type='submit' value='Next Page' name='submit'></td></tr>";
echo "</form>";

}
?>
=================================================
page3.php
-------------

<?php
session_start();
include ('../contentdb.php');
include ('../header.php');

$q2 = $_GET["$q"];
$_SESSION[$q2] = $_GET['$q'];

$_SESSION[$q1];
$_SESSION[$q2];
$_SESSION[$type];

$display = mysql_query("SELECT * FROM quiz where category ='$type' ORDER BY qnumber ASC LIMIT 20,10");

$myvar = $_POST['formVar'];
echo "<tr><td>myvar:$myvar</td></tr>";

echo $_Session[$name];

if ($submit) {

echo "<tr><td>";
echo "<form method=post action='../check/check.php' name=myform>";
while ($row = mysql_fetch_array($display)) {

$qnumber = $row["qnumber"];
$id = $row["id"];
$question = $row["question"];
$opt1 = $row["opt1"];
$opt2 = $row["opt2"];
$opt3 = $row["opt3"];
$answer = $row["answer"];
$q = $row["q"];

echo "<tr><td>";
echo "<tr><td colspan=10 align=left><b>$qnumber. $question</b></td></tr>";
echo "<tr><td><input type='hidden' name=\"q$id\" value=''></td></tr>";
echo "<tr><td colspan=10 align=left><input type=radio name=\"q$id\" value=\"$opt1\">$opt1</td></tr>
<tr><td colspan=10 align=left><input type=radio name=\"q$id\" value=\"$opt2\">$opt2</td></tr>
<tr><td colspan=10 align=left><input type=radio name=\"q$id\" value=\"$opt3\">$opt3</td></tr>";
echo "<tr><td><br></td></tr>";
}
echo "<tr><td><input type='button' value='Previous' onClick=javascript:history.back()>";

echo "<td><input type='hidden' name='formVar' value=''></td>";
echo "<td><input type='submit' value='Submit' name='submit'></td></tr>";
echo "</form>";
}
?>

==========================================================
check.php
--------------
<?php
session_start();
include("../contentdb.php");
include('../header.php');

$_SESSION[$q1];
$_SESSION[$q2];
$_SESSION[$type];

$display = mysql_query("SELECT * FROM quiz where category='$type' LIMIT 0,30",$db);

if ($submit)
{
$score = 0;

while ($result = mysql_fetch_array($display))
{
$answer = $result["answer"];
$q = $result["q"];

if ($$q == $answer)
{
$score++;
}
}

$total = 30;

echo "<tr>";
echo "<td>";
echo "<p align=left><b>You scored $score out of $total</b></p>";
echo "<p>";

if ($score == $total) {
echo "<p align=left>Congratulations! You got every question right!</p>";
}
elseif ($score/$total < 0.34) {
echo "<p align=left>Not the best score.</p>";
}
elseif ($score/$total > 0.67) {
echo "<p align=left>Well done! You certainly know your stuff.</p>";
}
else {
echo "<p align=left>Not bad - but there were a few that caught you out!</p>";
}

echo "<b><p align=left>Here are the answers:</p></b>";

echo "<table border=0 align=left >";
$display = mysql_query("SELECT * FROM $table where category='$type' ORDER BY qnumber ASC LIMIT 0,30",$db);
while ($row = mysql_fetch_array($display)) {

$number = $row ["qnumber"];
$question = $row["question"];
$answer = $row["answer"];
$q = $row["q"];

echo "<tr align=left><td><br><b>$number. $question</b></td></tr>";

if ($$q == $answer)
{
echo "<tr align=left><td><img src=../images/check.jpg height=22 width=22>You answered <font color=red><b><u>${$q}</u></b></font>, which is <font color=red><b>CORRECT!</b></font></td></tr>";
}

elseif ($$q == "") {
echo "<tr align=left><td><img src=../images/question.jpg height=15 width=15>You didn't select an answer. The answer is <font color=red><b><u>$answer</u></b></font></td></tr>";
}

else {
echo "<tr><td align=left><img src=../images/wrong.jpg height=15 width=15>You answered <b><u>${$q}</u></b>. The answer is <font color=red><b><u>$answer</u></b></font></td></tr>";
}

}
echo "</table></p>";
echo "<br />";

}
echo "<br />";
echo "<br />";
echo "<br />";
echo "<br />";
echo "<tr><td><a href='../student/subject.php'>Take New Test?</a></td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
echo "<tr><td><a href='admin.php'><img src='../images/home.gif'></td></tr></a>";
echo "<tr><td>HOME</td></tr>";
echo "<tr><td>&nbsp;</td></tr>";

?>

<tr>
<td colspan="2"><a href=""><img src="../images/m01.jpg" border="0"></a><a href=""><img src="../images/m02.jpg" border="0"></a><a href=""><img src="../images/m03.jpg" border="0"></a><a href=""><img src="../images/m04.jpg" border="0"></a><a href=""><img src="../images/m05.jpg" border="0"></a></td>
</tr>
Post Reply