我正在编写代码进行在线测试,在自动提交时遇到问题


i am writing code to conduct online test , got trouble in auto submit

我用过PHP,JS,Mysql和Html,除了自动提交和计时器之外,一切都在工作。

20 分钟后,它应该使用用户选择的选项自动提交并存储在 mysql 中。 弹出窗口"TimesUp 并告诉您的答案已提交"。

但它的弹出时间增加了味精,而不是自动提交和执行 PHP 代码以在 MySQL 中存储值。

<html>
<head>
</head>
<body>
<form action="" method="REQUEST">

<b>Enter Username:</b><input type="text" name="username" value=""/><br>
<b>Enter Password: </b><input type="password" name="password" value=""/><br>
<input type="submit" value="submit" name="submit"/>
<input type="reset" value="reset" name="reset"/>
</form>
<?php

if (isset($_REQUEST['submit'])) 
{
$username=$_REQUEST['username'];
$password=$_REQUEST['password'];
mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("demo") or die(mysql_error()); 
$result=mysql_query("select * from employees where name='$username' and pass='$password'") 
 or die(mysql_error()); 

if(mysql_num_rows($result)==0)
{
print "<br/>";
print "<b>Incorrect Username/Password!!!</b>";
}
else
{
print "<br/>";
print "<b>Login successful!!!</b><br/><br/>";
print "<script>window.close()</script>";
print "<a href=hello.php><script>window.open('hello.php')</script></a>";
}
}
?>
</body>
</html>

code for hello.php 
<!DOCTYPE html>
<html>
<head>
<script  type="text/javascript">
document.onmousedown=disableclick;
status="Right Click Disabled";
function disableclick(event)
{
  if(event.button==2)
   {
     alert(status);
     return false;    
   }
}
function timedText()
{
var x=document.getElementById('txt');
var t1=setTimeout(function(){x.value="20 min "},9000);
var t20m=setTimeout(function(){x.value="20 min"},60000);
var t19m=setTimeout(function(){x.value="19 min"},120000);
var t18m=setTimeout(function(){x.value="18 min"},180000);
var t17m=setTimeout(function(){x.value="17 min"},240000);
var t16m=setTimeout(function(){x.value="16 min"},300000);
var t15m=setTimeout(function(){x.value="15 min"},360000);
var t14m=setTimeout(function(){x.value="14 min"},420000);
var t13m=setTimeout(function(){x.value="13 min"},480000);
var t12m=setTimeout(function(){x.value="12 min"},540000);
var t11m=setTimeout(function(){x.value="11 min"},600000);
var t10m=setTimeout(function(){x.value="10 min"},660000);
var t9m=setTimeout(function(){x.value="9 min"},720000);
var t8m=setTimeout(function(){x.value="8 min"},780000);
var t7m=setTimeout(function(){x.value="7 min"},840000);
var t6m=setTimeout(function(){x.value="6 min"},900000);
var t5m=setTimeout(function(){x.value="5 min"},960000);
var t4m=setTimeout(function(){x.value="4 min"},1020000);
var t3m=setTimeout(function(){x.value="3 min"},1080000);
var t2m=setTimeout(function(){x.value="2 min"},1140000);
var t1m=setTimeout(function(){x.value="1 min"},1200000);
var t59=setTimeout(function(){x.value="59 sec "},1201000);
var t58=setTimeout(function(){x.value="58 sec "},1202000);
var t57=setTimeout(function(){x.value="57 sec "},1203000);
var t56=setTimeout(function(){x.value="56 sec "},1204000);
var t55=setTimeout(function(){x.value="55 sec "},1205000);
var t54=setTimeout(function(){x.value="54 sec "},1206000);
var t53=setTimeout(function(){x.value="53 sec "},1207000);
var t52=setTimeout(function(){x.value="52 sec "},1208000);
var t51=setTimeout(function(){x.value="51 sec "},1209000);
var t50=setTimeout(function(){x.value="50 sec "},1210000);
var t49=setTimeout(function(){x.value="49 sec "},1211000);
var t48=setTimeout(function(){x.value="48 sec "},1212000);
var t47=setTimeout(function(){x.value="47 sec "},1213000);
var t46=setTimeout(function(){x.value="46 sec "},1214000);
var t45=setTimeout(function(){x.value="45 sec "},1215000);
var t44=setTimeout(function(){x.value="44 sec "},1216000);
var t43=setTimeout(function(){x.value="43 sec "},1217000);
var t42=setTimeout(function(){x.value="42 sec "},1218000);
var t41=setTimeout(function(){x.value="41 sec "},1219000);
var t40=setTimeout(function(){x.value="40 sec "},1220000);
var t39=setTimeout(function(){x.value="39 sec "},1221000);
var t38=setTimeout(function(){x.value="38 sec "},1222000);
var t37=setTimeout(function(){x.value="37 sec "},1223000);
var t36=setTimeout(function(){x.value="36 sec "},1224000);
var t35=setTimeout(function(){x.value="35 sec "},1225000);
var t34=setTimeout(function(){x.value="34 sec "},1226000);
var t33=setTimeout(function(){x.value="33 sec "},1227000);
var t32=setTimeout(function(){x.value="32 sec "},1228000);
var t31=setTimeout(function(){x.value="31 sec "},1229000);
var t30=setTimeout(function(){x.value="30 sec "},1230000);
var t29=setTimeout(function(){x.value="29 sec "},1231000);
var t28=setTimeout(function(){x.value="28 sec "},1232000);
var t27=setTimeout(function(){x.value="27 sec "},1233000);
var t26=setTimeout(function(){x.value="26 sec "},1234000);
var t25=setTimeout(function(){x.value="25 sec "},1235000);
var t24=setTimeout(function(){x.value="24 sec "},1236000);
var t23=setTimeout(function(){x.value="23 sec "},1237000);
var t22=setTimeout(function(){x.value="22 sec "},1238000);
var t21=setTimeout(function(){x.value="21 sec "},1239000);
var t20=setTimeout(function(){x.value="20 sec "},1240000);
var t19=setTimeout(function(){x.value="19 sec "},1241000);
var t18=setTimeout(function(){x.value="18 sec "},1242000);
var t17=setTimeout(function(){x.value="17 sec "},1243000);
var t16=setTimeout(function(){x.value="16 sec "},1244000);
var t15=setTimeout(function(){x.value="15 sec "},1245000);
var t14=setTimeout(function(){x.value="14 sec "},1246000);
var t13=setTimeout(function(){x.value="13 sec "},1247000);
var t12=setTimeout(function(){x.value="12 sec "},1248000);
var t11=setTimeout(function(){x.value="11 sec "},1249000);
var t10=setTimeout(function(){x.value="10 sec "},1250000);
var t9=setTimeout(function(){x.value="9 sec "},1251000);
var t8=setTimeout(function(){x.value="8 sec "},1252000);
var t7=setTimeout(function(){x.value="7 sec "},1253000);
var t6=setTimeout(function(){x.value="6 sec "},1254000);
var t5=setTimeout(function(){x.value="5 sec "},1255000);
var t4=setTimeout(function(){x.value="4 sec "},1256000);
var t3=setTimeout(function(){x.value="3 sec "},1257000);
var t2=setTimeout(function(){x.value="2 sec "},1258000);
var t01=setTimeout(function(){x.value="1 sec "},1259000);
var t0=setTimeout(function(){x.value="0 sec "},1260000);*/
var wc=setTimeout(function(){
    document.getElementById("test").submit();       
    window.close();
    window.open('timesup.html');
    },9000);
}
 </script>
</head>
<body onload="timedText()" oncontextmenu="return false">
<h4 align="Center">All the Best <br/></h4>
<form id = "test" name="test" method="REQUEST">
<p align='right'><b>Time left : </b><input type="text" id="txt" /></p>
<p align='left'>Enter Your Mail_id:<input type="text" id="username" name="username"/></p>
<pre><p><b>Note:</b>
1. <strong><i><u>Please Enter your Email id in the above text box</u></i></strong> otherwise your answers will not be corrected.
2. Answer all the question, there is no negative markings.
3. Time given to answer all 30 questions is 20 min.</p></pre> 

<br>
<p align="left"><b>Question 1 : </b>A wheel that has 6 cogs is meshed with a larger wheel of 14 cogs. 
When the smaller <br/> wheel has made 21 revolutions, then the number of revolutions 
mad by the larger wheel is:<br/></p>
<input type="radio" name="q1" value="no" /><label>4</label><br>
<input type="radio" name="q1" value="no" /><label>9</label><br>
<input type="radio" name="q1" value="yes" /><label>12</label><br>
<input type="radio" name="q1" value="no" /><label>49</label><br>
<br />
<input type="submit" name="Submit" />
<p align="left"><b>Question 2 : </b>A wheel that has 6 cogs is meshed with a larger wheel of 14 cogs. 
When the smaller <br/> wheel has made 21 revolutions, then the number of revolutions 
mad by the larger wheel is:<br/></p>
<input type="radio" name="q2" value="yes" /><label>4</label><br>
<input type="radio" name="q2" value="no" /><label>9</label><br>
<input type="radio" name="q2" value="no" /><label>12</label><br>
<input type="radio" name="q2" value="no" /><label>49</label><br>
<br />
<p align="left"><b>Question 3 : </b>A wheel that has 6 cogs is meshed with a larger wheel of 14 cogs. 
When the smaller <br/> wheel has made 21 revolutions, then the number of revolutions 
mad by the larger wheel is:<br/></p>
<input type="radio" name="q3" value="no" /><label>4</label><br>
<input type="radio" name="q3" value="no" /><label>9</label><br>
<input type="radio" name="q3" value="no" /><label>12</label><br>
<input type="radio" name="q3" value="yes" /><label>49</label><br>
<br />
<p align="left"><b>Question 1 : </b>A wheel that has 6 cogs is meshed with a larger wheel of 14 cogs. 
When the smaller <br/> wheel has made 21 revolutions, then the number of revolutions 
mad by the larger wheel is:<br/></p>
<input type="radio" name="q4" value="no" /><label>4</label><br>
<input type="radio" name="q4" value="no" /><label>9</label><br>
<input type="radio" name="q4" value="yes" /><label>12</label><br>
<input type="radio" name="q4" value="no" /><label>49</label><br>
<br />
<p align="left"><b>Question 2 : </b>A wheel that has 6 cogs is meshed with a larger wheel of 14 cogs. 
When the smaller <br/> wheel has made 21 revolutions, then the number of revolutions 
mad by the larger wheel is:<br/></p>
<input type="radio" name="q5" value="yes" /><label>4</label><br>
<input type="radio" name="q5" value="no" /><label>9</label><br>
<input type="radio" name="q5" value="no" /><label>12</label><br>
<input type="radio" name="q5" value="no" /><label>49</label><br>
<br />
<p align="left"><b>Question 3 : </b>A wheel that has 6 cogs is meshed with a larger wheel of 14 cogs. 
When the smaller <br/> wheel has made 21 revolutions, then the number of revolutions 
mad by the larger wheel is:<br/></p>
<input type="radio" name="q6" value="no" /><label>4</label><br>
<input type="radio" name="q6" value="no" /><label>9</label><br>
<input type="radio" name="q6" value="no" /><label>12</label><br>
<input type="radio" name="q6" value="yes" /><label>49</label><br>
<br />
<input type="submit" name="Submit" />
</form>
<?php
echo '<p id="inphp"><script>alert("hoooo");</script></p>';
if (isset($_REQUEST['Submit'])) 
{
echo '<script>alert("voila");</script>';
$op1=$_REQUEST["q1"];
$op2=$_REQUEST["q2"];
$op3=$_REQUEST["q3"];
$op4=$_REQUEST["q4"];
$op5=$_REQUEST["q5"];
$op6=$_REQUEST["q6"];
mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("demo") or die(mysql_error()); 
//$DBName = "demo"; 
$username=$_GET['username'];
//$dbTable = $DBName.".".$username; 

mysql_query("Create TABLE $username(Question_No varchar(10),Selected_Answer varchar(10))") 
 or die("Enter your mail id / Enter Valid mail id ");  

mysql_query("insert into $username values('Q1','$op1')")
or die(mysql_error());
mysql_query("insert into $username values('Q2','$op2')")
or die(mysql_error());
mysql_query("insert into $username values('Q3','$op3')")
or die(mysql_error());
mysql_query("insert into $username values('Q4','$op4')")
or die(mysql_error());
mysql_query("insert into $username values('Q5','$op5')")
or die(mysql_error());
mysql_query("insert into $username values('Q6','$op6')")
or die(mysql_error());
print "<br/>Thank you $username<br/><br/>";
print "Your Answers as been submitted";
print "<a href=hello.php><script>window.open('final.html')</script></a>";
print "<a href=hello.php><script>window.close('hello.php')</script></a>";
}
?>
</body>
</html>

我希望以下代码可以帮助您自动提交表单。

只需将此代码复制粘贴到新页面中即可运行。

您将在20分钟后看到提交按钮将自动单击并显示一条消息。

根据这个概念,您无法在特定时间后自动提交


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" 
                 type="text/javascript"></script>
<script>
var submitForm = function() {
    $("input[name='submit']").click();
}
function waitSpecificTime(minute)
{
    setTimeout(submitForm, 1000*60*minute) //20 min
}
waitSpecificTime(20); // 20 min
</script>
<input type="submit" value="submit" name="submit" onclick="alert('test');"/>