...

View Full Version : some error in this snippet but i couldnt work it out



hima
04-03-2010, 01:16 PM
Hi,
i'm hima. i m new in IT field,i know lil bit of php .Currently 'm working on a online quiz project..i faced problem at displaying of quiz question n counting its marks. coding is as below.. help me out..



<FORM METHOD=POST ACTION="">
<P>YOU HAVE ONLY 5 MINUTES ....</P>
<INPUT TYPE="submit" NAME="submit" value='END TEST'>
<?php
$sr=1;
for($sr=1;$sr<=3;$sr=$sr+1)
{
include'db.php';
$sql=mysql_query("select * from que_ans where sr='$sr'");
$row=mysql_fetch_array($sql) or die(mysql_error());
?>

<TABLE>
<TR>
<TD>Ques:<?PHP echo $row['sr']."<BR>" ?></TD>
<TD><?PHP echo $row['que']."<BR>" ?></TD>
</TR>
</TABLE>
<UL>
<LI><INPUT TYPE="radio" NAME="ans" value='<?php echo $row['op1']?>'><?php echo $row['op1']; ?>
<LI><INPUT TYPE="radio" NAME="ans" value='<?php echo $row['op2']?>'><?php echo $row['op2']; ?>
<LI><INPUT TYPE="radio" NAME="ans" value='<?php echo $row['op3']?>'><?php echo $row['op3']; ?>
<LI><INPUT TYPE="radio" NAME="ans" value='<?php echo $row['op4']?>'><?php echo $row['op4']; ?>
</UL>
</FORM>

<?PHP
if(isset($_POST['submit']))
{
include'db.php';
$mark=0;

if((isset($_POST['op1'])) && ($row['op1']==$row['ans']))
{
$mark=$mark+1;
}
if((isset($_POST['op2'])) && ($row['op2']==$row['ans']))
{
$mark=$mark+1;
}
if((isset($_POST['op3'])) && ($row['op3']==$row['ans']))
{
$mark=$mark+1;
}
if((isset($_POST['op4'])) && ($row['op4']==$row['ans']))
{
$mark=$mark+1;
}

}
}
$result=$mark;
echo "your marks are '$result'";

?>

feras_wilson
04-10-2010, 12:33 PM
You are missing a } for the loop:


<?php
$sr=1;
for($sr=1;$sr<=3;$sr=$sr+1)
{
include'db.php';
$sql=mysql_query("select * from que_ans where sr='$sr'");
$row=mysql_fetch_array($sql) or die(mysql_error());
?>

Change this to this:

<?php
$sr=1;
for($sr=1;$sr<=3;$sr++)
{
include 'db.php';
$sql=mysql_query("SELECT * FROM que_ans WHERE sr='$sr'");
$row=mysql_fetch_array($sql) or die(mysql_error());
}
?>

Fou-Lu
04-10-2010, 07:31 PM
This is the wrong forum, moving from php snippets to php.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum