2017-01-28 29 views
0

我想從用戶確認之前刪除的條目確認之前刪除

我呼籲單擊刪除功能

<li><img src="delete1.png" onClick="delete_records();" alt="delete_records" /></li> 

的funcion保存在.js文件作爲

function delete_records() 
{ 
document.frm.action = "delete.php"; 
document.frm.submit(); 
} 

的delete.php是如下

<?php require 'connections/connections.php'; ?> 
<?php require 'includes/higherauth.php';// for user access level check 
?> 

<?php 
// To stop accessing the page without login 

if(isset($_SESSION["id"])){ 
}else{ 
header('Location: logIn.php'); 
} 
?> 
<?php 

error_reporting(0); 
$rado = $_POST['rado']; 
$chkcount = count($rado); 

if(!isset($rado)) 
{ 
    ?> 
    <script> 
    alert('At least one checkbox Must be Selected !!!'); 
    window.location.href = 'account.php'; 
    </script> 
    <?php 
} 
else 
{ 
    for($i=0; $i<$chkcount; $i++) 
    { 

     $del = $rado[$i]; 
     $sql=$con->query("DELETE FROM mntr WHERE id=".$del); 
    } 

    if($sql) 
    { 
     ?> 
     <script> 
     alert('<?php echo $chkcount; ?> Records Was Deleted !!!'); 
     window.location.href='account.php'; 
     </script> 
     <?php 
    } 
    else 
    { 
     ?> 
     <script> 
     alert('Error while Deleting , TRY AGAIN'); 
     window.location.href='account.php'; 
     </script> 
     <?php 
    } 
} 
?> 

請幫我添加一個警告確認刪除

+0

的可能的複製[如何顯示一個確認消息之前刪除?](HTTP ://stackoverflow.com/questions/9139075/how-to-show-a-confirm-message-before-delete) –

回答

1

一個簡單的方法就是添加一個確認及測試響應

function delete_records() 
{ 
    var conf= confirm("Do you really want delete?"); 
    if (conf== true){ 
     document.frm.action = "delete.php"; 
     document.frm.submit(); 
    }else{ 
     return; 
    } 
} 
+0

感謝您的幫助:) – user3521051

+0

@ user3521051好,如果我的答案是正確的,請標記爲接受.. 。看到這裏怎麼 http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – scaisEdge

+0

如果我有兩個用戶訪問級別,我怎麼能檢查相同也刪除行之前用_SESSION變量,如果($ _ SESSION [ 「的UserLevel」] == '2'){ \t \t> \t \t <?PHP的 \t} – user3521051