删除功能不起作用?

时间:2013-07-11 05:37:32

标签: php

我想知道为什么这段代码不起作用?该按钮执行正确的确认序列,但记录实际上并未删除。我从工作按钮复制并粘贴了代码,我认为在传输过程中我错过了指定细节?

if (isset($_GET['deleteseries'])) {
    echo 'Do you really want to delete ' 
        . $_GET['series'] 
        . '? <a  href="editstock.php?yesdelete=' 
        . $_GET['id'] 
        . '">Yes</a> | <a href="editstock.php">No</a>';
    exit();
}

if (isset($_GET['yesdelete'])) {
    $deleteSQL = sprintf("DELETE FROM series WHERE id='%s' LIMIT 1",
        GetSQLValueString($_GET['yesdelete'], "int"));

    mysql_select_db($database_connectmysql, $connectmysql);
    $Result1 = mysql_query($deleteSQL, $connectmysql) or die(mysql_error());
    header("location: editstock.php"); 
    exit();
}

使用此按钮:

<input name="deleteseries" 
    type="button" id="deleteseries" 
    value="delete" 
    style="width:20%; float:right" 
    onclick="window.location.href = '?deleteseries=delete&id=<?php echo $row_seriesrecordset['id']; ?>&series=<?php echo $row_seriesrecordset['series']; ?>'"/>

2 个答案:

答案 0 :(得分:0)

试试这个:

if (isset($_GET['yesdelete'])) {
    $deleteSQL = sprintf("DELETE FROM series WHERE id='%s' LIMIT 1",
        GetSQLValueString($_GET['yesdelete'], "int"));

    mysql_select_db($database_connectmysql, $connectmysql);
    $Result1 = mysql_query($deleteSQL, $connectmysql) or die(mysql_error());
    echo "deleted entry with ID ".$_GET['yesdelete'];
    exit;
    header("location: editstock.php"); 
    exit();
}

该条目被删除了什么?也许你传递了错误的“yesdelete”参数(错误的ID)..

答案 1 :(得分:-2)

一切都是正确的,只是你在下面的代码中犯了一个小错误:

if (isset($_GET['yesdelete'])) {
    $deleteSQL = sprintf("DELETE FROM series WHERE id='. $_GET['yesdelete'] LIMIT 1",
        GetSQLValueString($_GET['yesdelete'], "int"));

    mysql_select_db($database_connectmysql, $connectmysql);
    $Result1 = mysql_query($deleteSQL, $connectmysql) or die(mysql_error());
    header("location: editstock.php"); 
    exit();
}