简体   繁体   中英

why is the alert box not displaying?

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>

I dont see where you execute confirmReset , maybe just write

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

at the end of your script

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){ 
...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM