PHP program for online examinations.
CODE:
online.php:
<?php
$con=mysql_connect("localhost","root","gasc");
mysql_select_db("gasc110",$con);
$res=mysql_query("select * from test");
?>
<html>
<head></head>
<body bgcolor="yellow">
<form action="test.php" method="post">
<?php
while($row=mysql_fetch_array($res))
{
$a=$a+1;
$s=u.$a;
$b=r.$a;
echo"$row[qno]";
echo" $row[question]"."<br>";
echo"<input type=\"radio\" name=\"$s\"value=\"$row[opt1]\">$row[opt1]"."<br>";
echo"<input type=\"radio\" name=\"$s\"value=\"$row[opt2]\">$row[opt2]"."<br>";
echo"<input type=\"radio\" name=\"$s\"value=\"$row[opt3]\">$row[opt3]"."<br>";
echo"<input type=\"hidden\" name=\"$b\"value=\"$row[ans]\">";
echo"</font>";
echo"<br>";
}
?>
<input type="submit" name="submit" value="ok">
</form>
</body>
</html>
$con=mysql_connect("localhost","root","gasc");
mysql_select_db("gasc110",$con);
$res=mysql_query("select * from test");
?>
<html>
<head></head>
<body bgcolor="yellow">
<form action="test.php" method="post">
<?php
while($row=mysql_fetch_array($res))
{
$a=$a+1;
$s=u.$a;
$b=r.$a;
echo"$row[qno]";
echo" $row[question]"."<br>";
echo"<input type=\"radio\" name=\"$s\"value=\"$row[opt1]\">$row[opt1]"."<br>";
echo"<input type=\"radio\" name=\"$s\"value=\"$row[opt2]\">$row[opt2]"."<br>";
echo"<input type=\"radio\" name=\"$s\"value=\"$row[opt3]\">$row[opt3]"."<br>";
echo"<input type=\"hidden\" name=\"$b\"value=\"$row[ans]\">";
echo"</font>";
echo"<br>";
}
?>
<input type="submit" name="submit" value="ok">
</form>
</body>
</html>
test.php:
<?php
$y=0;
for($i=1;$i<=5;$i++)
{
$q=$_POST['u'.$i];
$w=$_POST['r'.$i];
if($q==$w)
{
$y=$y+1;
}
}
echo "your marks:$y";
//echo include('online.php'); //if you want ..add this...
?>
$y=0;
for($i=1;$i<=5;$i++)
{
$q=$_POST['u'.$i];
$w=$_POST['r'.$i];
if($q==$w)
{
$y=$y+1;
}
}
echo "your marks:$y";
//echo include('online.php'); //if you want ..add this...
?>
Comments
Post a Comment