我在頁面上顯示的每條記錄後都有一個SQL刪除按鈕。我確切地知道按鈕應該做什麼,但它不起作用!我甚至呼應$sql
,以確保它是正確的,並顯示以下內容:SQL刪除查詢顯示,但不採取行動
DELETE * FROM recensies WHERE ID ='508a7a732ef67' AND email ='[email protected]*****.nl'
當我看在phpMyAdmin記錄我可以看到,有恰好與此信息的記錄,但對別人也有必須是,這是我的代碼,我相信你會明白我的意思。
<?php
// Up here I connect to my DB, no problems there..
$query = "SELECT * FROM recensies ORDER BY timestamp DESC";
$result = mysql_query($query) or die(mysql_error());
if (isset($_POST['verwijderen']))
{
$IDdelete = mysql_real_escape_string($_POST['ID']);
$emaildelete = mysql_real_escape_string($_POST['email']);
$sql = "DELETE * FROM recensies "
. "WHERE ID ='$IDdelete' AND email ='$emaildelete'";
mysql_query($sql);
echo $sql;
}
while ($row = mysql_fetch_array($result))
{
?>
<form method="post">
<tr>
<td><?php echo $row['cijfer']; ?></td>
<td><input type="text" name="ID" value="<?php echo $row['ID']; ?>"></input></td>
<td><?php $newb = substr($row['beoordeling'], 0, 30); echo $newb; ?>..</td>
<td><?php echo $row['voornaam']; ?> <?php echo $row['achternaam']; ?></td>
<td><input type="text" name="email" value="<?php echo $row['email']; ?>"></td>
<td><?php $datum = date("j/n/y", strtotime($row[timestamp])); echo $datum; ?></td>
<td><input type="submit" value="Verwijderen" name="verwijderen"></td>
</tr>
</form>
<?php
}
?>
</table>
</div>
</div>
我只是找不到我的錯誤!
刪除總是意味着整排的,這就是爲什麼SQL不允許提*或任何字段名稱。刪除意味着刪除不刪除。如果您不通過使用where來指定行,則從sometable刪除..刪除所有行。 – Sami