Jump to content

Passing value onto script and checking if its the right ans


bumdeal2

Recommended Posts

Hey guys i have 2 scripts PlayGame.php and Grad.php.

 

What i need to do is pass the variable that is the correct answer onto the grad.php and if its correct it gives you a percentage however when it comes ot the correcting in grad it does not seem to be getting the value!Help would be truely appreciated?

 

 

 

 

PlayGame.php

<?php



include('database_access_param.php');
include('auth.php');


$right=0;

$qid=$_POST['qid'];
$quesid=$_POST['quesid'];
$totalCorrect=$_POST['totalCorrect'];
$score=$_POST['score'];
$taken=$_POST['taken'];
import_request_variables("pgc","");


if(isset($_GET['quesid']))
{

   $quesid=$_GET['quesid'];
}


if(isset($_GET['qid']))
{

   $qid=$_GET['qid'];

}
if(isset($_GET['totalCorrect']))
{

   $totalCorrect=$_GET['totalCorrect'];

}
if(isset($_GET['score']))
{

   $score=$_GET['score'];

}
if(isset($_GET['taken']))
{

   $taken=$_GET['taken'];

}

    mysql_connect( $hostname, $dbuser, $dbpassword)
        or die ( 'Unable to connect to server' );



    mysql_select_db($dbname )
        or die ( 'Unable to select database' );


    $sql = "SELECT * FROM questiona WHERE qid = '$qid' && quesid = '$quesid' ";




                print("</head>");
                print('<BODY onLoad="goNewWin()">');
                print('<form action="grad.php?qid=$qid&quesid=$quesid&totalCorrect=$totalCorrect&taken=$taken" method="post" id="quiz">');
                print('<table class="report" align=left width=100%>');

                print('<tr><td> </td></tr>');


                $result=mysql_query($sql) or die ('Unable execute the query');
;



                if(mysql_numrows($result))
                {
                                $row = mysql_fetch_row($result);
                                {

                                $questid=$row[0];
                                $quesid=$row[1];
                                $question=$row[2];
                                $ranswer=$row[3];
                                $ranswer1=$row[4];
                                $ranswer2=$row[5];
                                $answer=$row[6];
                                $qid=$row[7];

$answer = array($ranswer,$ranswer1,$ranswer2,$answer);
shuffle ($answer);



print('<body>');



        print('<tr><td >'.$quesid.'   '.$question.'</td>'.$Quiz_Topic.'</tr>');

        print('<input type= hidden name=qid value="'.$qid.'">');

        print('<input type= hidden name=totalCorrect value="'.$totalCorrect.'">');

        print('<input type= hidden name=quesid value="'.$quesid.'">');

        print('<input type= hidden name=score value="'.$score.'">');

        print('<input type= hidden name=taken value="'.$taken.'">');

        print('<tr><td><input type="radio" name="answer" id="answer" value="'.$answer[0].'">   '.$answer[0].'</td></tr>');

        print('<tr><td><input type="radio" name="answer" id="answer" value="'.$answer[1].'">   '.$answer[1].'</td></tr>');

        print('<tr><td><input type="radio" name="answer" id="answer" value="'.$answer[2].'">   '.$answer[2].'</td></tr>');

        print('<tr><td><input type="radio" name="answer" id="answer" value="'.$answer[3].'">   '.$answer[3].'</td></tr>');

        print('<tr><td> <input type=hidden name=answer id="answer" value="'.$answer[3].'"><input type= hidden name=qnumber value="'.$question.'"></tr>');


        }
        print('<tr><td colspan=2><input type=submit name=submit value="Submit" ><input type=reset name=reset value="Clear" ></td></tr></table>');


        print('</form>');

        }
else
        {

         echo "<div id='results'>Your result is:  $score%</div>";
        print('<input type =hidden name=score value="'.$score.'">');
        print('</form>');

        }


?>

 

 

Grad.php

<?php


include('auth.php');
include('database_access_param.php');
import_request_variables("pgc","");

$quesid = $_POST['quesid'];
$qid= $_POST['qid'];
$answer = $_POST['answer'];
$totalCorrect = $_POST['totalCorrect'];
$answer = $_POST['answer'];
$score = $_POST['score'];



$exist=0;
$cday= date('d');
$cmonth= date('m');
$cyear= date('Y');


$dbcurrent_date=$cyear.'-'.$cmonth.'-'.$cday;



  $db_link=mysql_connect($hostname, $dbuser, $dbpassword) or die("Unable to connect to the server!");

                mysql_select_db($dbname) or die("Unable to connect to the database.");


                $ssql = "SELECT scoreid,qid,username,score,taken,qdate FROM scores WHERE
                username = '".$user."' AND
                qid = '$qid'";





if($quesid < 11)

{
$answer1 = $_POST["answer"];

if ($answer1 == "answer")
{
$totalCorrect++;



            $score = $totalCorrect/$quesid*100;

            $quesid++;



header("location:PlayGame.php?quesid=$quesid&qid=$qid&totalCorrect=$totalCorrect&score=$score&taken=$taken");



}

else if ($answer1 != "answer")
{

$score =$totalCorrect/$quesid*50;

            $quesid++;



header("location:PlayGame.php?quesid=$quesid&qid=$qid&totalCorrect=$totalCorrect&score=$score&taken=$taken");
}









if($quesid=11)
{


$taken=1;



$isql="insert into scores(scoreid,username,score,qid,taken,qdate) values
                                                 (0, '".$user."',".$score.",".$qid.",".$taken.",'".$dbcurrent_date."')";


        echo "<div id='results'>Your result is:  $subTotal%</div>";

                                                if(!mysql_query($isql))
                                                {
                                                echo mysql_errno() . "";
                                                echo mysql_error() . "<BR>";
                                                }


}
}



include('PlayGame.php');


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.