从Javascript到PHP从数据库中删除

I have a link that's generated from a entry in a database, and I need to be able to delete that link. I have the DELETE query in my PHP, and a JavaScript confirm that works just fine, but confirming won't activate the PHP query. Here's the code:

JavaScript:

<script language="JavaScript" type="text/javascript">

    function deldoc(docid, docname)
    {
       if (confirm("Are you sure you want to delete '" + docname + "'"))
       {
          window.location.href = '<?php echo DIREMPLOYEE;?>?deldoc=' + docid;
       }
    }
</script>

PHP:

if(isset($_GET['deldoc'])){ 
    $deldoc = $_GET['deldoc'];
    $deldoc = mysql_real_escape_string($deldoc);
    $sql = mysql_query("DELETE FROM Documents WHERE docid = '$deldoc'") or die(mysql_error());
        $_SESSION['success'] = "Document Deleted"; 
        header('Location: ' .DIREMPLOYEE);
    exit();
}

When I press the OK button on the Confirm popup, it takes me to the Index page, but it's not deleting the document, and it's not giving me an error. Instead, it just tacks the docid onto the end of the directory URL, so it looks like this:

http://domain.com/employee?deldoc=7

Any ideas on how I can fix this?

Your SQL query should be something like this:

mysql_query("DELETE FROM Documents WHERE docid = '$deldoc'")

Warning:

mysql_ functions are deprecated, use mysqli or PDO. Also your code is not safe. It's vulnerable to SQL injections.