为什么不显示警告框?
这是我的代码。如果存储在文本文件中的重置日期等于当前日期并且表(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道你在哪里执行confirmReset,也许只是写
在脚本的末尾
I dont see where you execute confirmReset , maybe just write
at the end of your script
verify() 返回 true/false,"true === 1" 不为 true。
只需像这样编写您的确认控件,
confirm() returns true/false, and "true === 1" is not true.
just write your confirm control like this,