PDO DELETE查询bindParam无效

时间:2016-04-07 02:27:38

标签: php pdo

我在准备PDO DELETE query时遇到问题。我不确定在这种情况下我需要如何构造bindParam。我收到了这个警告:

  

警告:PDOStatement :: execute():SQLSTATE [HY093]:参数号无效:参数未定义

我做错了什么?

if(isset($_POST['delete'])) {
    $id = $_POST['id'];
    $stmt = $dbc->prepare("DELETE FROM users WHERE id = ?");
    $stmt->bindParam(' :id', $id);
    $stmt->execute();
}

<form method="POST">
            <tr>
                <td><input name="id" value="<?php echo $row['id'];?>" readonly></td>
                <td><input name="first" value="<?php echo $row['first'];?>"></td>
                <td><input name="last" value="<?php echo $row['last'];?>"></td>
                <td><input name="product" value="<?php echo $row['product'];?>"></td>
                <td><button name="save" type="submit">Save</button></td>
                <td><button name="delete" type="submit">Delete</button></td>
            </tr>
        </form>

0 个答案:

没有答案