javascript
  • php
  • 2017-08-17 49 views 1 likes 
    1

    以下是我的刪除代碼使用php,我想獲得確認後刪除鏈接被點擊從用戶使用php。如何從用戶刪除確認刪除查詢之前使用php

    <?php 
    include('conn.php'); 
    $query=mysql_query("DELETE FROM mark WHERE student_id='$_GET[st_id]'"); 
    if($query) 
        { 
         echo ("<SCRIPT LANGUAGE='JavaScript'> 
        window.alert('Succesfully deleted') 
        window.location.href='mark-details1.php'; 
        </SCRIPT>"); 
        } 
        else 
        { 
         echo "Check your Server"; 
        } 
        ?> 
    

    請任何人都可以告訴我該怎麼做?提前致謝!

    +0

    1:從來沒有一個調用刪除鏈接 - 從一個訪問Google蜘蛛和你的數據庫是空的。 2.使用方法Ajax請求:「DELETE」並顯示返回消息 – mplungjan

    +0

    請不要再使用'mysql_ *'函數。它們在PHP5中被棄用,並在PHP7中被刪除。使用MySQLi或PDO準備語句來防止mysql注入。 – Jer

    +0

    @mplungjan如果刪除身份驗證部分後面,則沒有任何問題。 – tilz0R

    回答

    3

    你可以在你的html標籤上使用這個javascript事件。

    onclick="return confirm('you sure?');" 
    

    ,你也可以使用這個:
    如果你的鏈接會發送一個得到像

    <?php 
    include('conn.php'); 
    if(isset($_GET['delete']) && is_numeric($_GET['delete'])==1){ 
        echo (a page with a form with confirmation question content that will sent a get for example (?checked_delete=(id))); 
    }elseif(isset($_GET["checked_delete"]) && is_numeric($_GET["checked_delete"])==1){ 
        // TODO : deleting record. 
        $query=mysql_query("DELETE FROM mark WHERE student_id='$_GET[checked_delete]'"); 
        header("location:mark-details1.php") 
    }else{ 
        echo (normal page); 
    } 
    ?> 
    
    +0

    鏈接點爲什麼人們給我的負面點? – Sonoo

    +0

    內聯事件處理程序通常不是一個好主意。在這種情況下,通過蜘蛛訪問的刪除鏈接將完全忽略您的腳本 – mplungjan

    +0

    在這個問題上沒有任何有關蜘蛛的話題。這將在正常情況下很好地工作。 – Sonoo

    0

    我建議使用Ajax 「刪除=(ID)?」。在這裏,我將使用jQuery使用

    $(function() { 
        $(".wh").on("click",function(e) { 
        e.preventDefault(); // cancel the click 
        $.get(this.href,function(data) { // does the student still exist? 
         if (confirm("delete" +data+"?")) { 
         $.get("otherphp.php?st_id="+$(this).data("id"),function(data) { 
          $(this).next().html(data); // show response 
         }); 
         } 
        }); 
        }); 
    }); 
    

    <a class="wh" data-id="<?=$rows['student_id']?>" href="edit-mark.php?st_id=<?=$rows['student_id']?>" title="Edit">Edit Marks</a><span class="confirmation"></span> 
    

    或者隱藏從蜘蛛

    在href
    <a class="wh" href="onlyworkswithjavascript.html" 
    data-id="<?=$rows['student_id']?>" data-href="edit-mark.php?st_id=<?=$rows['student_id']?>" 
    title="Delete">Delete Marks</a><span class="confirmation"></span> 
    
    
    $(function() { 
        $(".wh").on("click",function(e) { 
        e.preventDefault(); // cancel the click 
        if (confirm("delete" +data+"?")) { 
         $.get($(this).data("href"),function(data) { 
         $(this).next().html(data); // show response 
         }); 
        } 
        }); 
    }); 
    
    相關問題