Javascript html表单已成功提交到表单操作,但未能插入数据库(2020年2月20日)

Javascript html表单已成功提交到表单操作,但未能插入数据库(2020年2月20日),javascript,php,mysql,wamp,Javascript,Php,Mysql,Wamp,我有自己的申请人评估工具,使用PHP、Javascript和Mysql。表格应填满答案,或在12分钟后自动提交,并将空白字段值设为零。它是全功能的,我会告诉你如何设置它 这应该插入到ghsexam.php中 <script> time = 720; interval = setInterval(function() { time--; document.getElementById('Label1').innerHTML = "" + time + " seconds" if (ti

我有自己的申请人评估工具,使用PHP、Javascript和Mysql。表格应填满答案,或在12分钟后自动提交,并将空白字段值设为零。它是全功能的,我会告诉你如何设置它

这应该插入到ghsexam.php中

<script>
time = 720;
interval = setInterval(function() {
time--;
document.getElementById('Label1').innerHTML = "" + time + " seconds"
if (time == 0) {
    // stop timer
    clearInterval(interval);
    // click
    document.getElementById('thebutton').click();            
}
}, 1000)

</script>

<form id="locForm" name="locForm" target="" action="/ghs/ghsadd.php" method="post" >


<font size="5">Last name*</font><br>
<input type="text" name="last_name" required><br>

<font size="5">First name*</font><br>
<input type="text" name="first_name" required><br>

<font size="5">Middle Initial</font><br>
<input type="text" name="middle_initial" ><br>


<font size="5"><p class="thick">Highest Educational Attainment*</p></font>

<font size="5">

<input class="checked" type="radio" name="educ_attain" value="hsalsgrad" checked /><br>
<input type="radio" name="educ_attain" value="hsalsgrad" required> High School Graduate / ALS 
Graduate<br>
<input type="radio" name="educ_attain" value="shsgrad" required> Senior High School Graduate<br>
<input type="radio" name="educ_attain" value="undergrad1" required> College Undergraduate 1 year<br> 
<input type="radio" name="educ_attain" value="undergrad2" required> College Undergraduate 2 years<br> 
<input type="radio" name="educ_attain" value="undergrad3" required> College Undergraduate 3 years<br> 
<input type="radio" name="educ_attain" value="undergrad4" required> College Undergraduate 4+ 
years<br>
<input type="radio" name="educ_attain" value="collegegrad" required> College Graduate<br>
</font><br>
<hr>
<font size="5"><p class="thick">Logic and Reasoning</p></font>

<p>You will be given 5 minutes to complete this portion.</p><br>

<font size="5"><p>The 4:25 P2P bus takes 1 hour and 45 minutes to arrive in 
Trinoma. If Joseph takes this bus, what time will he arrive in 
Trinoma? *</p>


<input class="checked" type="radio" name="logic1" value="0" checked /> </br>
<input type="radio" name="logic1" value="0" required> 7:05 <br>
<input type="radio" name="logic1" value="0" required> 6:25<br>
<input type="radio" name="logic1" value="1" required> 6:10<br>
<input type="radio" name="logic1" value="0" required> 5:55<br>

<br>

<p>Janine’s shoes cost $44.50, her pants cost $20.80 and her t-shirt
cost $14.95. What is the total of her purchases? *</p>

<input class="checked" type="radio" name="logic2" value="0" checked /> </br>
<input type="radio" name="logic2" value="0" required> 85.25<br>
<input type="radio" name="logic2" value="1" required> 80.25<br>
<input type="radio" name="logic2" value="0" required> 82.55<br>
<input type="radio" name="logic2" value="0" required> 80.55<br>

<br>

<p>Which number represents the smallest amount? *</p>

<input class="checked" type="radio" name="logic3" value="0" checked /> </br>
<input type="radio" name="logic3" value="0" required> 1/12<br>
<input type="radio" name="logic3" value="0" required> 2/9<br>
<input type="radio" name="logic3" value="0" required> 15/200<br>
<input type="radio" name="logic3" value="1" required> 3/140<br>
</font>
<br>

<input name="submit" type='submit' id='thebutton' value='Submit' 
onclick="document.getElementById('Label2').innerHTML = 'Clicked!'"></input>

<p hidden id='Label1'> Time </p>
<p hidden id='Label2' style='color:red;'> </p>

时间=720;
间隔=设置间隔(函数(){
时间--;
document.getElementById('Label1')。innerHTML=“”+时间+“秒”
如果(时间==0){
//停止计时器
间隔时间;
//点击
document.getElementById('thebutton')。单击();
}
}, 1000)
姓氏*

名字*

中间首字母

最高学历*


高中毕业生/ALS 毕业
高中毕业生
大学本科1年
大学本科2年
大学本科3年
大学本科4+以上 年
大学毕业生


逻辑与推理

您将有5分钟的时间完成此部分。


4:25的P2P巴士需要1小时45分钟才能到达 特里诺玛。如果约瑟夫坐这辆公共汽车,他什么时候到 特里诺玛*


7:05
6:25
6:10
5:55

Janine的鞋子44.50美元,裤子20.80美元,t恤衫 费用14.95美元。她总共买了多少*


85.25
80.25
82.55
80.55

哪个数字代表最小的数量*


1/12
2/9
15/200
3/140

时间

这应该插入ghsadd.php中

<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ghsexam_database" ;
$conn = mysqli_connect($servername, $username, $password, $dbname);

if (isset($_POST['submit'])){

$last_name =$_POST['last_name'];
$first_name =$_POST['first_name'];
$middle_initial =$_POST['middle_initial'];
$educ_attain =$_POST['educ_attain'];

$logic1 =$_POST['logic1'];
$logic2 =$_POST['logic2'];
$logic3 =$_POST['logic3'];

$grammar1 =$_POST['grammar1'];
$grammar2 =$_POST['grammar2'];
$grammar3 =$_POST['grammar3'];
$grammar4 =$_POST['grammar4'];
$grammar5 =$_POST['grammar5'];

$ghs_essay =$_POST['ghs_essay'];

$reading1 =$_POST['reading1'];
$reading2 =$_POST['reading2'];
$reading3 =$_POST['reading3'];
$reading4 =$_POST['reading4'];

$listening1 =$_POST['listening1'];
$listening2 =$_POST['listening2'];

$query = mysqli_query($conn, "INSERT INTO ghs_table (last_name, first_name, middle_initial,         
educ_attain, logic1, logic2, logic3, grammar1, grammar2, grammar3, grammar4, grammar5, ghs_essay, 
reading1, reading2, reading3, reading4, listening1, listening2, datentime) values ('$last_name', 
'$first_name', '$middle_initial', '$educ_attain', '$logic1', '$logic2', '$logic3', '$grammar1', 
'$grammar2', '$grammar3', '$grammar4', '$grammar5', '$ghs_essay', '$reading1', '$reading2', 
'$reading3', '$reading4', '$listening1', '$listening2', now() )");

}

else{
    echo" ";
}

mysqli_close($conn); 

?>

<html>
<link rel="icon" href="ghsfavicon.png" type="image/gif" sizes="16x16">
<head>

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="ghsfavicon.png" type="image/gif" sizes="16x16">
</head>
<body>

<br>

<center><h1>Exam Successfully Submited!</h1></center>
<center><h3><a href="/ghs/ghsexamhome.php">Submit Another Exam</a></h3></center>


</body>
</html>

危险
插入
。我建议在准备好的语句中使用mysqli。我希望你的连接信息真的在一个单独的页面上,在一个有700权限的文件夹中。
不是一个容器,你不应该有
,但是insert语句在另一个php页面上?好吧,你没有检查任何php或mysql错误,因此,如果您没有收到任何错误消息,您真的不应该感到惊讶。。。