[英]why is the alert box not displaying?
這是我的代碼。 如果存儲在文本文件中的重置日期等於當前日期並且來自表(mysql)的數據不為零,則應顯示警告框。然后應將值重置為零並刪除其他記錄。 我試過回顯if語句,它是1。不確定為什么警告框沒有彈出。
<?php
function reset1(){
$sql=mysql_query("UPDATE tbl_txbookStock SET suppliedQuantity=0, boughtQuantity=0");
$sql=mysql_query("DELETE FROM tbl_order");
$sql=mysql_query("DELETE FROM tbl_order_book");
//overwrite date
$myFile = "config/config.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$resetDate = fread($fh, filesize($myFile));
fwrite($fh,date("m/d/Y",strtotime("+1 years")));
fclose($fh);
}
function getCurrentDate(){
return date('m/d/Y');
}
function resetDateIsToday($resetDate){
$itIs=false;
if($resetDate==getCurrentDate())
$itIs=true;
return $itIs;
}
function isReset(){
$isReset=false;
if(countZeroQuantities()==countBooks()){
$isReset=true;
}
return $isReset;
}
function countBooks(){
$sql=mysql_query("select count(bookID) as count from tbl_textbook");
$row=mysql_fetch_array($sql);
return $row['count'];
}
function countZeroQuantities(){
$sql=mysql_query("select count(bookID) as count FROM `tbl_txbookStock` where suppliedQuantity>0 OR boughtQuantity>0");
$row=mysql_fetch_array($sql);
return $row['count'];
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>TEXTBOOK ORDERING SYSTEM</title>
<link rel="stylesheet" href="templatemo_style.css">
<?php if (!isset($_SESSION['loggedin'])){ {?>
<?php if(resetDateIsToday(getResetDate())&&!isReset()){?>
<script type="text/javascript">
<!--
function confirmReset(){
var answer = confirm ("Reset is scheduled today.Do you really want to reset?")
if (answer===1){
<?php reset1();?>
window.location="index.php";
}else{
alert('Records not reset...');
window.location="index.php";
}}
// -->
</script>
<? }}}?>
</head>
<body>
</body>
</html>
我看不到您在哪里執行ConfirmReset,也許只是寫
window.onload =function(e){
confirmReset();
}
在腳本的末尾
Confirm()返回true / false,並且“ true === 1”不為true。
像這樣編寫您的確認控件,
var answer = confirm ("Reset is scheduled today.Do you really want to reset?")
if (answer){
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.