为什么不显示警告框?

发布于 2025-01-08 15:38:32 字数 2009 浏览 0 评论 0原文

这是我的代码。如果存储在文本文件中的重置日期等于当前日期并且表(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>

This is my code. It should display the alert box if the reset date stored in a textfile is equal to the current date and the data from the tables(mysql) are not zero.. Then it should reset the values to zero and delete other records. I've tried echoing the if statement and it's 1.Not sure why the alert box is not popping up..

<?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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花辞树 2025-01-15 15:38:32

我不知道你在哪里执行confirmReset,也许只是写

window.onload =function(e){
confirmReset();
}

在脚本的末尾

I dont see where you execute confirmReset , maybe just write

window.onload =function(e){
confirmReset();
}

at the end of your script

晨与橙与城 2025-01-15 15:38:32

verify() 返回 true/false,"true === 1" 不为 true。

只需像这样编写您的确认控件,

var answer = confirm ("Reset is scheduled today.Do you really want to reset?")
if (answer){ 
...
}

confirm() returns true/false, and "true === 1" is not true.

just write your confirm control like this,

var answer = confirm ("Reset is scheduled today.Do you really want to reset?")
if (answer){ 
...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文