gpt4 book ai didi

javascript - 使用 Javascript PHP MySQL 的在线考试计时器

转载 作者:行者123 更新时间:2023-11-29 21:00:04 25 4
gpt4 key购买 nike

以下代码用于在线考试。当用户完成并单击“获取结果”按钮后,用户将被重定向到结果页面。现在的问题是它不会发送到结果页面。

此代码运行正常

echo "<div class=\"module form-module\">";
echo "<form name=myfm class=form method=post id=myfm action=quiz.php>";
echo "<table width=100%> <tr> <td width=30>&nbsp;<td> <table border=0>";
$n=$_SESSION[qn]+1;
echo "<tR><td><span class=style2>Question ". $n .": $row[2]</style><br><br>";
echo "<input type=radio name=ans value=1>&nbsp;$row[3]<br>";
echo "<input type=radio name=ans value=2>&nbsp;$row[4]<br>";
echo "<input type=radio name=ans value=3>&nbsp;$row[5]<br>";
echo "<input type=radio name=ans value=4>&nbsp;$row[6]<br>";
echo "<input type=radio name=ans value=5>&nbsp;$row[7]<br>";
if($_SESSION[qn]<mysql_num_rows($rs)-1)
echo "<tr><td><br><input type=submit class=button id=submit name=submit value='Next Question'></form></div>";
else
echo "<tr><td><input type=submit id=submit class=button name=submit value='Get Result'></form></div>";

当用户完成后,就会进入这个流程

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,ans5,true_ans,your_ans) values ('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$row[8]','$ans')") or die(mysql_error());
if($ans==$row[8])
{
$_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,ans5,true_ans,your_ans) values ('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$row[8]','$ans')") or die(mysql_error());
if($ans==$row[8])
{
$_SESSION[trueans]=$_SESSION[trueans]+1;
}
echo "<h1 class=head1> Result</h1>";
$_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>";
mysql_query("insert into mst_result(login,test_id,test_date,score) values('$login',$tid,'".date("d/m/Y")."',$_SESSION[trueans])") or die(mysql_error());
mysql_query("insert into mst_adminresult(login,test_id,score) values('$login',$tid,$_SESSION[trueans])") or die(mysql_error());
unset($_SESSION[qn]);
unset($_SESSION[sid]);
unset($_SESSION[tid]);
unset($_SESSION[trueans]);
exit;

现在我添加了一个计时器

var c=10;
var t;
timedCount();

function timedCount()
{

var hours = parseInt( c / 3600 ) % 24;
var minutes = parseInt( c / 60 ) % 60;
var seconds = c % 60;

var result = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);


$('#timer').html(result);
if(c == 0 )
{
$('#myfm').submit();
}
c = c - 1;
t = setTimeout(function()
{
timedCount()
},
1000);
}

问题是它不会提交。它只是保持在同一页面上。我首先尝试通过创建一个警报框来检查它,它起作用了,确保计时器代码正常工作。那么这个问题的解决方案是什么,以便我可以采用相同的流程来显示结果并将答案发送到我的数据库?

最佳答案

echo "<div class=\"module form-module\">";
echo "<form name=myfm class=form method=post id=myfm action=quiz.php>";
echo "<table width=100%> <tr> <td width=30>&nbsp;<td> <table border=0>";
$n=$_SESSION[qn]+1;
echo "<tR><td><span class=style2>Question ". $n .": $row[2]</style><br><br>";
echo "<input type=radio name=ans value=1>&nbsp;$row[3]<br>";
echo "<input type=radio name=ans value=2>&nbsp;$row[4]<br>";
echo "<input type=radio name=ans value=3>&nbsp;$row[5]<br>";
echo "<input type=radio name=ans value=4>&nbsp;$row[6]<br>";
echo "<input type=radio name=ans value=5>&nbsp;$row[7]<br>";
if($_SESSION[qn]<mysql_num_rows($rs)-1)
echo "<tr><td><br><input type=submit class=button id=submit name=next value='Next Question'></form></div>";
else
echo "<tr><td><input type=submit id=submit class=button name=results value='Get Result'></form></div>";

php

if($_POST['next'] && $_POST['ans'])
{ echo "Yay! You POST-ed!";
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,ans5,true_ans,your_ans) values ('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$row[8]','$ans')") or die(mysql_error());
if($ans==$row[8])
{
$_SESSION[trueans]=$_SESSION[trueans]+1;
}
$_SESSION[qn]=$_SESSION[qn]+1;
}
else if($_POST['results'] && $_POST['ans'])
{ echo "Yay! You POST-ed!";
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,ans5,true_ans,your_ans) values ('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$row[8]','$ans')") or die(mysql_error());
if($ans==$row[8])
{
$_SESSION[trueans]=$_SESSION[trueans]+1;
}
echo "<h1 class=head1> Result</h1>";
$_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>";
mysql_query("insert into mst_result(login,test_id,test_date,score) values('$login',$tid,'".date("d/m/Y")."',$_SESSION[trueans])") or die(mysql_error());
mysql_query("insert into mst_adminresult(login,test_id,score) values('$login',$tid,$_SESSION[trueans])") or die(mysql_error());
unset($_SESSION[qn]);
unset($_SESSION[sid]);
unset($_SESSION[tid]);
unset($_SESSION[trueans]);
//you can use session_destory();
exit;

关于javascript - 使用 Javascript PHP MySQL 的在线考试计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37312299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com