这是我的代码。如果存储在文本文件中的重置日期等于当前日期并且来自表(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>
答案 0 :(得分:0)
我没有看到你执行确认重置的地方,也许只是写
window.onload =function(e){
confirmReset();
}
在脚本的末尾
答案 1 :(得分:0)
confirm()返回true / false,“true === 1”不正确。
只需写下你的确认控件,
var answer = confirm ("Reset is scheduled today.Do you really want to reset?")
if (answer){
...
}