i want to save the score detail in php to db

Category: Dreamweaver

InMotionFans
n/a Points
Asked:
2014-08-08 1:24 am EST

Hits: 47
<?php include_once('include/header.php');?>
<?php
error_reporting(E_NOTICE ^ E_ALL);
session_start();
if(!isset($_SESSION['username']) || ($_SESSION['username']==''))
{
header("location:exam.php");
}
else
{
?>
<script language="javascript">

var mins
var secs;

function cd() {
mins = 1 * m("5"); // change minutes here
secs = 0 + s(":01");
redo();
}

function m(obj) {
for(var i = 0; i < obj.length; i++) {
if(obj.substring(i, i + 1) == ":")
break;
}
return(obj.substring(0, i));
}

function s(obj) {
for(var i = 0; i < obj.length; i++) {
if(obj.substring(i, i + 1) == ":")
break;
}
return(obj.substring(i + 1, obj.length));
}

function dis(mins,secs) {
var disp;
if(mins <= 9) {
disp = " 0";
} else {
disp = " ";
}
disp += mins + " .";
if(secs <= 9) {
disp += "0" + secs;
} else {
disp += secs;
}
return(disp);
}

function redo() {
secs--;
if(secs == -1) {
secs = 59;
mins--;
}
document.cd.disp.value = dis(mins,secs); // setup additional displays here.
if((mins == 0) && (secs == 0)) {
window.alert(" Hey Time is up. Press OK to continue.");
window.location = "test.php" // redirects to specified page once timer ends and ok button is pressed
} else {
cd = setTimeout("redo()",1000);
}
}

function init() {
cd();
}
window.onload = init;
</script>

<body>
<div class="wrapper">
<div class="container">
<?php include_once('include/header1.php');?>


<center><table>
<tr align="right"><td><form name="cd">
<label>
<span class="labe" ><font color="#000099" size="+1">Remaining Time</font></span>:
<input name="disp" type="text" class="clock" id="txt" value="10:00" size="10" readonly="true" align="right" border="1" />
<span class="labe"><font color="#000099" size="+1">Minutes</font></span>
</form></td></tr>
</table></center>
<?php

include_once('db/db.php'); ?>

<form name="quiz" method="post" action="quiz.php">
<?php if($_POST["do"]=="finish")
{
$rans=$_POST["rans"];
$tq=$_POST["tq"];
$end=$_POST["end"];

$startposition=$_POST["startposition"];

echo "<table cellpadding='5px' align='center' style='border:1px solid silver' width='800px'
bgcolor='green' height='auto'>";
echo "<tr><td height='50px'>Total Question Attempt</td><td>",$tq,"</td><tr>";
echo "<tr><td height='50px'>Correct Answer</td><td>",$rans,"</td></tr>";
echo "<tr><td height='50px'>Wrong Answer</td><td>",$tq-$rans,"</td></tr>";
echo "<tr><td height='50px'>Correct Answer Percentage</td><td>",$rans/$tq*100,"%</td></tr>";
echo "<tr><td height='50px'>Wrong Answer Percenntage</td><td>",($tq-$rans)/$tq*100,"%</td></tr>";

echo "</table><br><br>";
$query="select * from quiz where qid<='$end' and qid>='$startposition'";
echo "<table cellpadding='5px' align='center' style='border:1px
solid silver' width='800px'>";
echo "<tr><th colspan='4' id='heading' style='color:black'>Online Quiz Test
Question</td></tr>";
$result=mysql_query($query);
while ($row = mysql_fetch_array($result)) {
echo "<tr><td style='color:black' height='50px' padding:'0px 10px 0px 0px'>",$row[0],"<td colspan='2' style='color:black' >",$row[1],"</td></tr><tr><td></td>";
echo "<td colspan='2' style='color:black' height='50px'>A. ",$row[2],"</td>";

echo "<td colspan='2' style='color:black' height='50px'>B. ",$row[3],"</td></tr>";

echo "<tr><td></td><td colspan='2' style='color:black'>C. ",$row[4],"</td>";
echo "<td colspan='1' style='color:black' height='50px'>D. ",$row[5],"</td></tr>";
echo "<tr><td colspan='4' align='right'
style='color:orange'>Correct option is ",strtoupper($row[6]),"</td></tr>";
echo "<tr><td colspan='4' align='right'
style='color:orange'><hr></td></tr>";
}
echo "</table>";

echo "<p align='right'><a href='#' onclick='window.print()'>Print</a></p>";
echo "<div style='visibility:hidden;display:none'>";
}

?>

<table cellpadding="5px" width="800px" height="300px" style="border:1px solid silver; font:Arial, Helvetica, sans-serif medium ; " >
<?php
$reg_no=$_GET["reg_no"];
$start=$_POST["start"];
$s=$_POST["startposition"];
if($start==NULL)
{
$start=$_GET["start"];
$s=$_GET["start"];
}
$useropt=$_POST["useropt"];
$qid=$_POST["qid"];
$rans=$_POST["rans"];
$name=$_POST["name"];
$totalquestion=$_POST["totalquestion"];

if($start==NULL)
{
$query="select * from quiz where qid='1' ";
}
else
{
$query="select * from quiz where qid='$start' ";
}


$result=mysql_query($query);
while ($row = mysql_fetch_array($result)) {
echo "<tr><td style='color:black' >",$row[0],"</td><td style='color:black'>",$row[1],"</td></tr><tr><td></td><td
style='color:black'><input type='radio' name='useropt' value='a' /> ",$row[2],"</td><td style='color:black'><input type='radio'
name='useropt' value='b' /> ",$row[3],"</td></tr><tr><td ></td><td style='color:black'><input type='radio'
name='useropt' value='c' /> ",$row[4],"</td><td style='color:black'><input type='radio' name='useropt' value='d' />
",$row[5],"</td></tr>";
echo "<tr ><td align='right'><input
type='hidden' name='name' value='",$name,"'><input type='hidden' name='start' value='",$row[0]+1,"'><input
type='hidden' name='qid' value='",$row[0],"'><input type='hidden' name='startposition' value='",$s,"'><input
type='submit' value='Next Question' style='width:60px'
height:'40px'
'color:#fff'
'background:#19235B'
'
'font-weight:bold'
'cursor:pointer'
'clear:both'><input type='hidden' name='totalquestion' value='",$totalquestion+1,"'>";
echo "</td></tr>";
}
echo "<tr><td colspan='4'>";
$query="select woptcode from quiz where qid='$qid'";
$result=mysql_query($query);
while ($row = mysql_fetch_array($result)) {
if(strcmp($row[0],$useropt)==0)
{
echo "<input type='hidden' name='rans' value='",$rans+1,"'>";
$rans=$rans+1;
}
else
echo "<input type='hidden' name='rans' value='",$rans,"'>";
}


echo "</td></tr>";
?>

</table>


</form>
<form method="post" action="quiz.php">
<input type="hidden" name="do" value="finish" />
<input type="hidden" name="rans" value="<?php echo $rans;?>" />
<input type="hidden" name="name" value="<?php echo $name;?>" />
<input type="hidden" name="tq" value="<?php echo $totalquestion;?>" />
<input type="hidden" name="end" value="<?php echo $start-1;?>" />
<input type="hidden" name="startposition" value="<?php echo $s;?>" />
<center><input type="submit" value="Finish Online Test" /></center>

</form>

<?php
}
?>

<div class="footer">
<p> 2013 Unicorn Institute Of Technology. All rights reserved.</p>
</div>
</div>
</div>
</label>
</label>
</body>
</html>
i want to store the total question attempted $tq,right answer rans ,wrong answer in the db and i also retrieve the score.

You must login before you can ask a follow up question.

You must login before you can submit an answer.

OTHER ANSWERS

0

Scott
Staff
20,848 Points
2014-08-08 7:38 am EST
If you need to save any data to the database, such as the $tq value, you simply need to 1) have a column in thee database to store it and then 2) create a SQL statement to update the database with that data. Depending on your database structure, this could either be an UPDATE or an INSERT statement.

Kindest Regards,
Scott M

You must login before you can post a comment about this answer.

Like this Question?

Related Articles

It looks like there are no related articles.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!