Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2010
    Location
    gujrat, country:India
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    some error in this snippet but i couldnt work it out

    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..


    PHP Code:
     <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'";

    ?>

  • #2
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts
    You are missing a } for the loop:
    Code:
    <?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:
    Code:
    <?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()); 
    }
    ?>
    

    Exp:
    PHP
    .NET

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    This is the wrong forum, moving from php snippets to php.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •