2012-02-24 131 views
0

這是我的代碼。如果存儲在文本文件中的重置日期等於當前日期並且來自表(mysql)的數據不爲零,它應該顯示警告框。然後它應該將值重置爲零並刪除其他記錄。我試着呼應的if語句,它的一禁止知道爲什麼警告框不會彈出.. 爲什麼警告框不顯示?

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

我希望你知道,''頁面之前總是執行甚至發送到客戶端。您無法通過JavaScript控制該PHP語句,因爲首先在服務器上評估PHP,並將結果發送給客戶端,然後再執行JavaScript。放入JavaScript'if'語句的效果與將PHP代碼塊放在最後的效果相同。而'<! - '是JavaScript中的語法錯誤。 – 2012-02-24 01:06:16

回答

0

我沒有看到你在哪裏執行confirmReset,也許只是寫

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

在腳本末尾

+0

哦,對,我會先嚐試刪除功能。 – user1077271 2012-02-24 01:28:47

0

confirm()返回true/false,並且「true === 1」不正確。

只寫你的證實控制這個樣子,

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