Jump to content

mysql errors in php


Ahmad Ijaz

Recommended Posts

Hey guys , i've made a project on online examination system...but i'm having a problem with the result page.

e.g if someOne do the exam within the time then it show a proper result...but if someone didn't complete his paper in time then when the time is up...it just show an error...please help...i will send the project...and this is my final year project...Thanks

Link to comment
Share on other sites

No, everything is just fine...but when time is up...it shows a pop up message , when you press Ok.. it just redirects you to the result page ...which doesn't contain the appropriate result....i want it to show the result like:::For Example ...there are 100 questions and you solved only 70 questions because time is up...

So the result should be like this

 

[Total Questions: 100

True : whatever

False: whatever

total solved:70 questions

percentage: e.g 55%..]

 

How to retreive this kinda data from database ...i just don't understand the logic...

if you have some time i can send my project,,,as well as the screen shots...

Thanks in advance...justsomeguy

Link to comment
Share on other sites

<?phpsession_start();include ("database.php");extract ($_POST);extract ($_GET);extract($_SESSION);/*$rs=mysql_query("select * from mst_question where test_id=$tid",$cn) or die(mysql_error());if($_SESSION[qn]>mysql_num_rows($rs)){unset($_SESSION[qn]);exit;}*/if(isset($subid) && isset($testid)){$_SESSION[sid]=$subid;$_SESSION[tid]=$testid;header("location:quiz.php");}if(!isset($_SESSION[sid]) || !isset($_SESSION[tid])){    header("location: index.php");}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[url=http://www.w3.org/TR/html4/loose.dtd]http://www.w3.org/TR/html4/loose.dtd[/url]"><html><head><title>Online Quiz</title>  <meta charset="utf-8" /><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link href="quiz.css" rel="stylesheet" type="text/css"></head><body bgcolor="#236">        <table hieght="250" align="center" class="paperTable" height="500"><tr>    <td>       <span class="style4">      <?php///include("header.php");/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////$rs=mysql_query("select * from mst_question where test_id=$tid",$cn) or die(mysql_error());if(!isset($_SESSION[qn])){        $_SESSION[qn]=0;    mysql_query("delete from mst_useranswer where sess_id='" . session_id() ."'") or die(mysql_error());    $_SESSION[trueans]=0;    }else /////if($submit=='Next Question' && ans==""){//////////    echo    $msg="Please Select any answer";//////    }/////////    else{    ////////////////////////////////////////////////////THIS IS FOR RESULT....        if($submit=='Next Question' && isset($ans))                {                mysql_data_seek($rs,$_SESSION[qn]);                $row= mysql_fetch_row($rs);                    mysql_query("insert into mst_useranswer(sess_id, test_id, que_des, ans1,ans2,ans3,ans4,true_ans,your_ans) values ('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$ans')") or die(mysql_error());                if($ans==$row[7])                {                            $_SESSION[trueans]=$_SESSION[trueans]+1;                }                $_SESSION[qn]=$_SESSION[qn]+1;        }        else if($submit=='Get Result' && isset($ans))        {                                mysql_data_seek($rs,$_SESSION[qn]);                $row=mysql_fetch_row($rs);                    mysql_query("insert into mst_useranswer(sess_id, test_id, que_des, ans1,ans2,ans3,ans4,true_ans,your_ans) values ('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$ans')") or die(mysql_error());                // include("result1.php");            //    echo "<h1 align=center><a href=result1.php> Result</a> </h1>";                                if($ans==$row[7])                {                            $_SESSION[trueans]=$_SESSION[trueans]+1;                }                             echo "<h1 class=head1> Result</h1>";                 echo "<hr />";                 echo "<br />";                 echo "Click on review link to view all the correct answers";                $_SESSION[qn]=$_SESSION[qn]+1;                echo "<Table align=center><tr class=tot><td>Total Question :<td> $_SESSION[qn]";                echo "<tr class=tans><td>True Answer :<td>".$_SESSION[trueans];                $w=$_SESSION[qn]-$_SESSION[trueans];                echo "<tr class=fans><td>Wrong Answer :<td> ".( $w);                    echo "</table>";                    echo "<br />";                $percentage=floor(($_SESSION[trueans]*100)/$_SESSION[qn]) ;                echo "You Scored : " .$percentage." %";                echo "<br />";                if($percentage>=70){                    echo "Congratulations! you passed the exam.";                    }                    else{                        echo "<br />";                        echo "<span class=fans>Sorry! you are failed.</span>";                        }                mysql_query("insert into mst_result(login,test_id,test_date,score) values('$login',$tid,'$date',$_SESSION[trueans])") or die(mysql_error());                echo "<h1 align=center><a href=review.php>>>>>> Review Question<<<<<<</a> </h1>";                echo "To pass this exam you'll have to score at least 70%.";                unset($_SESSION[qn]);                unset($_SESSION[sid]);                unset($_SESSION[tid]);                unset($_SESSION[trueans]);                exit;                  echo "<br />";                        }}//////////////////////////////////////////////////////////////////////////if there are no quesitons....OR the exam paper is not ready yet...$rs=mysql_query("select * from mst_question where test_id=$tid",$cn) or die(mysql_error());if($_SESSION[qn]>mysql_num_rows($rs)-1){//unset($_SESSION[qn]);echo "<h1 class=head1>This Exam Paper is not ready yet.<br />Please Contact the Administrator OR the Incharge of Examination.</h1>";//session_destroy();echo "Please <a href=sublist.php> Start Again</a>";exit;}//////////////////////////////////////////////////////////////////////////This is the paper area...Through which someone take the exam....mysql_data_seek($rs,$_SESSION[qn]);$row= mysql_fetch_row($rs);include("timer2.php");////////Timer is included here.........echo "<br />";echo "<br />";echo "<hr />";echo "<form name=myfm method=post action=quiz.php>";echo "NOTE : Select one RadioButton located at the front of each question";echo "<table width=100%><table align=center> <tr> <td width=30> <td> <table border=1 cellpad=2 cellspace=2>";$n=$_SESSION[qn]+1;echo "<tR><td ><span class=head1>Que ".  $n .": $row[2]</style>";echo "<tr><td height=30 class=style8>$row[3]</td><td><input type=radio name=ans value=1></td>";echo "<tr><td height=30 class=style8>$row[4]</td><td><input type=radio name=ans value=2></td>";echo "<tr><td height=30 class=style8 >$row[5]</td><td><input type=radio name=ans value=3></td>";echo "<tr><td height=30 class=style8>$row[6]</td><td><input type=radio name=ans value=4></td>";if($_SESSION[qn]<mysql_num_rows($rs)-1)echo "<tr><td height=30><input type=submit name=submit  value='Next Question' ></form>";elseecho "<tr><td><input type=submit name=submit value='Get Result'></form>";echo "</table></table>"; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////?>    </span></td></tr></table></body></html>
Now the above coding is correct ...it shows the proper result.....when someone does the paper within the time....So everything is just fine with this.... But how to do coding for when the time is upExample: there are 100 questions..and you did only 80 due to the shortage of time...and in 80 questions there will be some true answers and some false answers...So the result should be like this...total questions:100attempted: 80true:whatever e.g 55false:whatever e.g 25percentage...55%
Link to comment
Share on other sites

It shouldn't matter how many questions they answered, the only thing that matters is how many they got correct. It doesn't matter if they didn't answer a question or if they got it wrong, it's still not correct. In your example above, you don't use the fact that they only answered 80 questions, since they got 55 correct their score is 55%.

  • Like 1
Link to comment
Share on other sites

Are you saying that if they only attempted 80 questions, didn't see 20 out of the 100 total, and they answered 55 correctly, then you want their score to be 55/80 instead of 55/100? If the score is still supposed to be 55/100 then it doesn't matter how many questions they saw, the only thing that matters is how many total questions are on the test and how many they got correct.

Link to comment
Share on other sites

I'm not a code writing or debugging service, I'm here to help people learn how to do it for themselves. This is your final year project, not mine. By the final year you should be able to know how to use a database. Your code there is already using a database, so what exactly do you not understand how to do?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...