I am having issues getting a PDO prepared DELETE
query
to work. I am unsure of how I need to structure the bindParam
in this instance. I get this warning:
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
What am I doing wrong?
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>