无法获取要执行的PDO删除语句

时间:2014-08-09 00:13:36

标签: php mysql pdo

我无法获取表单发布变量,然后让我的PDO语句执行删除。我知道变量$得到的[WID]确实在我的表单中存储了正确的值。问题在于将变量从这个表单传递给下面的代码来执行delete语句。我得到的错误是:参数号无效:参数未定义

//这是php / PDO代码:

 if(isset($_POST['remove'])){
 $the_WID = $_POST['WID'];
 echo "here is the WID" . $the_WID;

 $dlt = "DELETE FROM writing WHERE writing.WID = :writing.WID";
 $stmtdlt = $dbh->prepare($dlt);
 $stmtdlt->bindParam(':writing.WID', $the_WID, PDO::PARAM_INT);                                           
 $stmtdlt->execute(); 
 }

//这是表格

<form action="" method="post">
<button type="submit">Delete</button>
<input TYPE="hidden" name="remove" VALUE="<?php $resulting[WID]; ?>">
</form>

1 个答案:

答案 0 :(得分:5)

  1. $the_WID = $_POST['WID'];应为$the_WID = $_POST['remove'];

  2. 您需要回应您的价值:value="<?php echo $resulting[WID]; ?>"

  3. the answer to this question开始,您似乎无法在占位符中使用.

  4.   

    BINDCHR = [:] [a-zA-Z0-9 _] +;

         

    您可以使用字母数字+下划线。

    将您的PHP更改为:

    if(isset($_POST['remove'])){
        $the_WID = $_POST['remove'];
        echo "here is the WID" . $the_WID;
    
        $dlt = "DELETE FROM writing WHERE writing.WID = :writingWID";
        $stmtdlt = $dbh->prepare($dlt);
        $stmtdlt->bindParam(':writingWID', $the_WID, PDO::PARAM_INT);                                           
        $stmtdlt->execute(); 
    }
    

    和您的HTML表单:

    <form action="" method="post">
    <button type="submit">Delete</button>
    <input type="hidden" name="remove" value="<?php echo $resulting[WID]; ?>">
    </form>