Good Morning.
I just started learning php about a month ago, i decided to try a project of my own. that is to develope an examination system. so far its been fun challenges and all. rite now, am stock at a point and i have tried every idea i know but to no avail.
this is the issue. i created a form using a loop
<?php
on the new page, i am able to receive all the values all values except the values posted from the radio buttons of the form
on the second page, this is wot is did
am not exactly sure if i did the right thing, but i guess its wrong cuz if it was right, it should have worked.
i am trying to compare the correct answers with the users option selected. and score him based on that. any idea would be appreciated.
i have attached a copy of the result page showing the error
I just started learning php about a month ago, i decided to try a project of my own. that is to develope an examination system. so far its been fun challenges and all. rite now, am stock at a point and i have tried every idea i know but to no avail.
this is the issue. i created a form using a loop
<?php
<form action="result.php" method ="POST">
//START CONNECTION
$con = mysql_connect("localhost","root","");
//test connection
if(!$con)
{
die("unable to connect");
}
else
{
$db = mysql_select_db('jamb')or die('Unable to select database');
// create and execute query
$sql = "SELECT * FROM QUEST WHERE COURSE_CODE='$course1' OR COURSE_CODE='$course2'OR COURSE_CODE='$course3'OR COURSE_CODE='$course4' ORDER BY COURSE_CODE";
$result = mysql_query($sql)
or die ('Error in query: sql. ' . mysql_error());
// check if records were returned
//resetcounter for name of radiobutton
$num=0;
//reset counter for the serial number of the questions
$sn=1;
// print each field
if (mysql_num_rows($result) > 0)
{
// print HTML table
echo '<table cellpadding=10 cellspacing=0 border=0>';
// iterate over record set
// print each field
while($row = mysql_fetch_row($result))
{
//get the course code of the question
$ccode=$row[1];
//if the course code changes,
if ($ccode2 != $ccode){
//display the new course code and the course title of the questions being answered
echo "<tr bgcolor='blue' style='font-weight: bolder; color: white'><td></td><td>$row[1]: $row[2] </td></tr>" ;
//reset counter for the serial number
$sn=1;
$ccode2=$ccode;
}
//display question
echo '<tr><td></td><td> <b>('.$sn.') ' .$txtQ =$row[3] . '</b></td></tr>';
//************************************
//display options
echo "<tr><td></td><td><input type='radio' name='$Answer[$num]' value='A'> (A) " . $row[4] . "</td></tr>";
echo "<tr><td></td><td><input type='radio' name='$Answer[$num]' value='B'> (B)/> " . $row[5] . "</td ></tr>";
echo "<tr><td></td><td><input type='radio' name='$Answer[$num]' value='C'> (C) " . $row[6] . "</td></tr>";
//*****************************************************************
//get the correct answer
$txtD = $row[7];
//determine the correct answer
if ($row[5] === $row[7])
{$ca[$num]='A';}
if ($row[4] === $row[7])
{$ca[$num]='B';}
if ($row[6] === $row[7])
{$ca[$num]='C';}
//*********************************
//display correct answer
echo "<tr><td></td><td> $ca[$num] $txtD</td></tr>";
//****************************************
//iscrease counters
$num=$num+1;
$sn=$sn+1;
//*****************************
//display green line
echo "<tr><td></td><td> <img src='images/LINE1.png' width=1035 height=2></td></tr>";
//***************************************************
//run loop
}
//display submit button
echo"<tr><td></td><td><input name='cmdSubmit' type='submit' value='SUBMIT PAPER' style='position:absolute;left:500px;z-index:16'></td></tr>";
//display green line
echo "<tr><td></td><td> <img src='images/LINE1.png' width=1035 height=2></td></tr>";
//colse table
echo '</table>';
//get total of all the questions
$qtotal=$num;
//post values
for ($I=0;$I<$qtotal;$I++){
//post correct answers
$_SESSION['ca[$I]']=$ca[$I];
//post users answers
$_SESSION['Answer[$I]']=$Answer[$I];
//close loop
}
//post other values
$_SESSION['sname']=$sname;
$_SESSION['reg']=$reg;
$_SESSION['course1']=$course1;
$_SESSION['course2']=$course2;
$_SESSION['course3']=$course3;
$_SESSION['course4']=$course4;
$_SESSION['qtotal']=$qtotal;
//************************************
}
else
{
// print error message
echo '<table cellpadding=10 cellspacing=0 border=0>';
echo '<tr><td>No Records found!!!</td></tr>';
echo'</table>';
}
//once processing is complete
// free result set
mysql_free_result($result);
// close connection to MySQL server
mysql_close($con);
}
//*********************************************
?>
on the new page, i am able to receive all the values all values except the values posted from the radio buttons of the form
on the second page, this is wot is did
<?php
session_start();
//get values
$sname=$_SESSION['sname'];
$reg=$_SESSION['reg'];
$course1=$_SESSION['course1'];
$course2=$_SESSION['course2'];
$course3=$_SESSION['course3'];
$course4=$_SESSION['course4'];
$qtotal=$_SESSION['qtotal'];
//initialize counters
$nwa=0;//number of wrong answers
$nca=0;//number of correct answers
//start loop
for ($I=0;$I<$qtotal;$I++)
{
//get correct answers
$ca[$I]=$_SESSION['ca[$I]'];
//get user answers
$ua[$I]= $_SESSION['Answer$I'];
//compare answers
if ($ua[$I]===$ca[$I]){
$nca=$nca+1;
}else{
$nwa=$nwa+1;
}
//this line can be removed. i just put it to check if the values posted are received
echo "The answer is $ca[$I]<BR/> but you chose $ua[$I]<BR/>";
}
//**********************************
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<meta name="generator" content="Web Page Maker V2">
<title>RESULT SLIP</title>
<style type="text/css">
/*----------Text Styles----------*/
.ws6 {font-size: 8px;}
.ws7 {font-size: 9.3px;}
.ws8 {font-size: 11px;}
.ws9 {font-size: 12px;}
.ws10 {font-size: 13px;}
.ws11 {font-size: 15px;}
.ws12 {font-size: 16px;}
.ws14 {font-size: 19px;}
.ws16 {font-size: 21px;}
.ws18 {font-size: 24px;}
.ws20 {font-size: 27px;}
.ws22 {font-size: 29px;}
.ws24 {font-size: 32px;}
.ws26 {font-size: 35px;}
.ws28 {font-size: 37px;}
.ws36 {font-size: 48px;}
.ws48 {font-size: 64px;}
.ws72 {font-size: 96px;}
.wpmd {font-size: 13px;font-family: 'Arial';font-style: normal;font-weight: normal;}
/*----------Para Styles----------*/
DIV,UL,OL /* Left */
{
margin-top: 0px;
margin-bottom: 0px;
}
</style>
<style type="text/css">
div#container
{
position:relative;
width: 884px;
margin-top: 0px;
margin-left: auto;
margin-right: auto;
text-align:left;
}
body {text-align:center;margin:0}
</style>
</head>
<body>
<?php
//compute score
?>
<div id="container">
<div id="image3" style="position:absolute; overflow:hidden; left:0px; top:0px; width:884px; height:809px; z-index:0"><img src="images/back.png" border=0 width=884 height=809></div>
<div id="image1" style="position:absolute; overflow:hidden; left:15px; top:0px; width:851px; height:100px; z-index:1"><img src="images/name.png" border=0 width=851 height=100></div>
<div id="text2" style="position:absolute; overflow:hidden; left:187px; top:771px; width:579px; height:15px; z-index:2"><div class="wpmd">
<div align=center><font color="#FFFFFF"><B>SERVICE AND INTEGRITY</B></font></div>
</div></div>
<div id="hr1" style="position:absolute; overflow:hidden; left:34px; top:91px; width:819px; height:17px; z-index:3">
<hr size=2 width=819>
</div>
<div id="hr2" style="position:absolute; overflow:hidden; left:37px; top:161px; width:819px; height:17px; z-index:4">
<hr size=2 width=819>
</div>
<div id="text1" style="position:absolute; overflow:hidden; left:37px; top:145px; width:209px; height:24px; z-index:5; background-color:#008000"><div class="wpmd">
<div><font class="ws14" color="#FFFFFF" face="Calibri"><B>STUDENT INFORMATION</B></font></div>
</div></div>
<div id="text3" style="position:absolute; overflow:hidden; left:297px; top:212px; width:410px; height:21px; z-index:6"><div class="wpmd">
<div><font class="ws14" color="#339966" face="Calibri"><B> <?php echo $sname;?></B></font></div>
</div></div>
<div id="text4" style="position:absolute; overflow:hidden; left:298px; top:182px; width:410px; height:21px; z-index:7"><div class="wpmd">
<div><font class="ws14" color="#339966" face="Calibri"><B> <?php echo $reg;?>
</B></font></div>
</div></div>
<div id="text5" style="position:absolute; overflow:hidden; left:170px; top:182px; width:124px; height:18px; z-index:8"><div class="wpmd">
<div><font class="ws12" color="#FF0000"><B>REG. NUMBER:</B></font></div>
</div></div>
<div id="text6" style="position:absolute; overflow:hidden; left:169px; top:211px; width:124px; height:18px; z-index:9"><div class="wpmd">
<div><font class="ws12" color="#FF0000"><B>FULL NAME:</B></font></div>
</div></div>
<div id="hr3" style="position:absolute; overflow:hidden; left:35px; top:273px; width:819px; height:17px; z-index:10">
<hr size=2 width=819>
</div>
<div id="text7" style="position:absolute; overflow:hidden; left:35px; top:258px; width:209px; height:24px; z-index:11; background-color:#008000"><div class="wpmd">
<div><font class="ws14" color="#FFFFFF" face="Calibri"><B>COURSE INFORMATION</B></font></div>
</div></div>
<div id="text10" style="position:absolute; overflow:hidden; left:272px; top:294px; width:561px; height:21px; z-index:12"><div class="wpmd">
<div><font class="ws14" color="#339966" face="Calibri"><B><?php echo $course1;?></B></font></div>
</div></div>
<div id="text11" style="position:absolute; overflow:hidden; left:169px; top:296px; width:104px; height:19px; z-index:13"><div class="wpmd">
<div><font class="ws12" color="#FF0000"><B>COURSE (1):</B></font></div>
</div></div>
<div id="hr4" style="position:absolute; overflow:hidden; left:35px; top:420px; width:819px; height:17px; z-index:14">
<hr size=2 width=819>
</div>
<div id="text14" style="position:absolute; overflow:hidden; left:35px; top:405px; width:209px; height:24px; z-index:15; background-color:#008000"><div class="wpmd">
<div><font class="ws14" color="#FFFFFF" face="Calibri"><B>STUDENT PERFORMANCE</B></font></div>
</div></div>
<div id="text15" style="position:absolute; overflow:hidden; left:480px; top:508px; width:347px; height:21px; z-index:16"><div class="wpmd">
<div><font class="ws14" color="#339966" face="Calibri"><B><?php echo $nwa;?></B></font></div>
</div></div>
<div id="text16" style="position:absolute; overflow:hidden; left:174px; top:511px; width:274px; height:18px; z-index:17"><div class="wpmd">
<div><font class="ws12" color="#FF0000"><B>NUMBER OF WRONG ANSWERS:</B></font></div>
</div></div>
<div id="text17" style="position:absolute; overflow:hidden; left:480px; top:476px; width:374px; height:21px; z-index:18"><div class="wpmd">
<div><font class="ws14" color="#339966" face="Calibri"><B><?php echo $nca;?></B></font></div>
</div></div>
<div id="text18" style="position:absolute; overflow:hidden; left:175px; top:480px; width:293px; height:18px; z-index:19"><div class="wpmd">
<div><font class="ws12" color="#FF0000"><B>NUMBER ANSWERED CORRECTLY:</B></font></div>
</div></div>
<div id="text19" style="position:absolute; overflow:hidden; left:481px; top:448px; width:361px; height:21px; z-index:20"><div class="wpmd">
<div><font class="ws14" color="#339966" face="Calibri"><B>
<?php
//display number of available questions
echo $qtotal;
?>
</B></font></div>
</div></div>
<div id="text20" style="position:absolute; overflow:hidden; left:173px; top:450px; width:319px; height:19px; z-index:21"><div class="wpmd">
<div><font class="ws12" color="#FF0000"><B>QUESTIONS TO ANSWER:</B></font></div>
</div></div>
<div id="hr5" style="position:absolute; overflow:hidden; left:38px; top:560px; width:819px; height:17px; z-index:22">
<hr size=2 width=819>
</div>
<div id="text21" style="position:absolute; overflow:hidden; left:38px; top:545px; width:209px; height:24px; z-index:23; background-color:#008000"><div class="wpmd">
<div><font class="ws14" color="#FFFFFF" face="Calibri"><B>PERCENTAGE SCORE</B></font></div>
</div></div>
<div id="text22" style="position:absolute; overflow:hidden; left:230px; top:581px; width:379px; height:56px; z-index:24"><div class="wpmd">
<div align=center><font class="ws36" color="#FF0000"><B><?php $x1=$nca/$qtotal*100;echo "$x1%"; ;?></B></font></div>
</div></div>
<div id="hr6" style="position:absolute; overflow:hidden; left:37px; top:656px; width:819px; height:17px; z-index:25">
<hr size=2 width=819>
</div>
<div id="text23" style="position:absolute; overflow:hidden; left:37px; top:641px; width:209px; height:24px; z-index:26; background-color:#008000"><div class="wpmd">
<div><font class="ws14" color="#FFFFFF" face="Calibri"><B>REMARK</B></font></div>
</div></div>
<div id="text24" style="position:absolute; overflow:hidden; left:198px; top:684px; width:450px; height:21px; z-index:27"><div class="wpmd">
<div align=center><font class="ws14" color="#339966" face="Calibri"><B>
<?php
if($x1<40){
echo 'YOU FAILED';
}
elseif($x1>=40 && $x1<=49){
echo 'YOU PASSED';
}
elseif($x1>=50 && $x1<59){
echo 'MANAGEABLE';
}
elseif($x1>=60 && $x1<=69){
echo 'VERY GOOD!!!';
}
else{
echo 'EXCELLENT!!!!!!';
}
?>
</B></font></div>
</div></div>
<div id="hr7" style="position:absolute; overflow:hidden; left:34px; top:108px; width:819px; height:17px; z-index:28">
<hr size=2 width=819>
</div>
<div id="text25" style="position:absolute; overflow:hidden; left:36px; top:98px; width:74px; height:18px; z-index:29"><div class="wpmd">
<div><font class="ws12" face="Calibri"><a href="http://localhost/jambexam.com/" title="CLICK TO RETURN TO MENU"><<RETURN</a></font></div>
</div></div>
<div id="text26" style="position:absolute; overflow:hidden; left:646px; top:146px; width:197px; height:21px; z-index:30"><div class="wpmd">
<div><font class="ws14" color="#339966" face="Calibri"><B>
<?php
//get date
$my_date=date("d/m/Y",strtotime("now"));
//display date
echo $my_date;?>
</B></font></div>
</div></div>
<div id="text27" style="position:absolute; overflow:hidden; left:606px; top:148px; width:46px; height:18px; z-index:31"><div class="wpmd">
<div><font class="ws12" color="#FF0000"><B>Date:</B></font></div>
</div></div>
<div id="text12" style="position:absolute; overflow:hidden; left:169px; top:323px; width:104px; height:19px; z-index:32"><div class="wpmd">
<div><font class="ws12" color="#FF0000"><B>COURSE (2):</B></font></div>
</div></div>
<div id="text13" style="position:absolute; overflow:hidden; left:169px; top:375px; width:104px; height:19px; z-index:33"><div class="wpmd">
<div><font class="ws12" color="#FF0000"><B>COURSE (4):</B></font></div>
</div></div>
<div id="text28" style="position:absolute; overflow:hidden; left:169px; top:349px; width:104px; height:19px; z-index:34"><div class="wpmd">
<div><font class="ws12" color="#FF0000"><B>COURSE (3):</B></font></div>
</div></div>
<div id="text8" style="position:absolute; overflow:hidden; left:272px; top:321px; width:561px; height:21px; z-index:35"><div class="wpmd">
<div><font class="ws14" color="#339966" face="Calibri"><B><?php echo $course2;?></B></font></div>
</div></div>
<div id="text9" style="position:absolute; overflow:hidden; left:272px; top:374px; width:561px; height:21px; z-index:36"><div class="wpmd">
<div><font class="ws14" color="#339966" face="Calibri"><B><?php echo $course4.'2';?></B></font></div>
</div></div>
<div id="text29" style="position:absolute; overflow:hidden; left:272px; top:347px; width:561px; height:21px; z-index:37"><div class="wpmd">
<div><font class="ws14" color="#339966" face="Calibri"><B><?php echo $course3;?></B></font></div>
</div></div>
</div></body>
</html>
am not exactly sure if i did the right thing, but i guess its wrong cuz if it was right, it should have worked.
i am trying to compare the correct answers with the users option selected. and score him based on that. any idea would be appreciated.
i have attached a copy of the result page showing the error