我正在尝试将倒数计时器达到0时将我的数据库属性从0更新为1.
这是我的代码:
<script language="JavaScript">
var timeleft;
var nextdue;
var tick = 1000;
function parseTime(t) {
var tt = ("0:00:" + t);
tt = tt.split(":").reverse();
return (tt[0] * 1000) + (tt[1] * 60000) + (tt[2] * 3600000);
}
function zeroPad(n) {
if (n < 10) return "0" + n;
return "" + n;
}
function makeTime(t) {
if (t < 0) return "0:00:00";
var tt = t + 999;
return Math.floor(tt / 3600000) + ":" +
zeroPad(Math.floor(tt / 60000) % 60) + ":" +
zeroPad(Math.floor(tt / 1000) % 60);
}
function startTimer() {
nextdue = new Date().getTime();
timeleft = parseTime(document.timerform.timerbox.value);
console.log(timeleft);
timeleft = document.getElementById("TL");
runTimer();
}
function runTimer() {
document.timerform.timerbox.value = makeTime(timeleft);
if (timeleft <= 0)window.location.href="closedDBphp.php";
else {
var timecorr = (new Date().getTime()) - nextdue;
if (timecorr > 0 && timecorr < 3000) {
timeleft -= (tick + timecorr);
nextdue += tick;
if (timeleft < 1) setTimeout("runTimer()", tick + timeleft);
else setTimeout("runTimer()", Math.max(1, tick - timecorr));
}
else {
nextdue = (new Date().getTime()) + tick;
timeleft -= tick;
if (timeleft < 1) setTimeout("runTimer()", tick + timeleft);
else setTimeout("runTimer()", tick);
}
}
}
这就是我在.jsp文件中显示倒计时器的方法:
<div><span id = "TL"></span></div>
这是PHP代码:
<?php
$servername = "localhost";
$username ="root";
$password ="root";
$dbname = "cyber";
//// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE pin SET closed= 1 ";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
?>
我很想知道我的代码出了什么问题,我也在使用Intellij的想法。请帮我提供建议, 我提前谢谢你们。