InMotion Hosting Support Center

i want to save the score detail in php to db

Category: Dreamweaver

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

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

var mins
var secs;

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

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

function s(obj) {
for(var i = 0; i < obj.length; i++) {
if(obj.substring(i, i + 1) == ":")
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;

function redo() {
if(secs == -1) {
secs = 59;
} = 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() {
window.onload = init;

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

<tr align="right"><td><form name="cd">
<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>

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

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


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
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'
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 ; " >

$query="select * from quiz where qid='1' ";
$query="select * from quiz where qid='$start' ";

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' />
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'
'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'";
while ($row = mysql_fetch_array($result)) {
echo "<input type='hidden' name='rans' value='",$rans+1,"'>";
echo "<input type='hidden' name='rans' value='",$rans,"'>";

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


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



<div class="footer">
<p> 2013 Unicorn Institute Of Technology. All rights reserved.</p>
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.



43,761 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?

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

Social Media Login

Social Login Joomla

Related Articles

Need more Help?


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:
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!