2014-03-01 95 views
0

嗨量這是我的新手問題... 我開始學習PHP的三天前... 這是我的問題... 例如 我有一個量的50時,我10值50成爲40 和通知提醒我,這個數字不到50 但仍subracted當我再次subract它subracted .....如何降低與通知

這裏是我的代碼

if(isset($_POST['submit'])){ 

$id = $_GET['id']; 
$old = $_POST['quantity']; 
$new = $_POST['quantity1']; 

$total = $new - $old; 


if($total < 50){ 

     echo "<h1 style='color: red'><center>CRITICAL LEVEL</center></h1>"; 
     echo "<script>window.open('inventory.php' , '_self');</script>"; 

} 


else{ 

$uiqry = $mysqli->prepare("UPDATE table_inventory SET quantity = ? WHERE id = ?"); 

$uiqry->bind_param('ii', $total,$id); 

$uiqry->execute(); 
$uiqry->close(); 
echo "<script>alert('Subracted');</script>"; 
echo "<script>window.open('inventory.php', '_self');</script>"; 


} 

} 

我當我的價值50和我subr從10的值現在是40的值,並警告通知我 ,當我把它再次由10的值變爲30和通知彈出再次 如何做到這一點 在此先感謝.. 對不起,我的繞口令英語..:D

+0

只要刪除'else {}'子句並始終執行UPDATE查詢。 –

回答

0
if(isset($_POST['submit'])){ 

    $id = $_GET['id']; 
    $old = $_POST['quantity']; 
    $new = $_POST['quantity1']; 

    $total = $new - $old; 


    if($total < 50){ 

     echo "<h1 style='color: red'><center>CRITICAL LEVEL</center></h1>"; 
     echo "<script>window.open('inventory.php' , '_self');</script>"; 

    } 

    $uiqry = $mysqli->prepare("UPDATE table_inventory SET quantity = ? WHERE id = ?"); 
    $uiqry->bind_param('ii', $total,$id); 

    $uiqry->execute(); 
    $uiqry->close(); 
    echo "<script>alert('Subracted');</script>"; 
    echo "<script>window.open('inventory.php', '_self');</script>"; 

}