SQL删除查询显示,但没有操作

时间:2012-10-29 21:50:12

标签: php sql database sql-delete

我的页面上显示的每条记录后都有一个SQL删除按钮。我有按钮应该做什么,但它不起作用!我甚至回应$sql以确保它是正确的,它显示以下内容:

DELETE * FROM recensies WHERE ID ='508a7a732ef67' AND email ='info@*****.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>

我找不到我的错误!

3 个答案:

答案 0 :(得分:3)

我不知道这是不是你的问题,但是DELETE语法不需要列列表(查询中的*): 你应该写

DELETE FROM recensies WHERE ID = ...

没有*

答案 1 :(得分:2)

我认为你需要从delete语句中删除*,所以这样:

DELETE FROM recensies WHERE ID ='508a7a732ef67' AND email ='info@*****.nl'

答案 2 :(得分:1)

更改

$sql = "DELETE * FROM recensies WHERE ID ='$IDdelete' AND email ='$emaildelete'";

$sql = "DELETE FROM recensies WHERE ID ='$IDdelete' AND email ='$emaildelete'";

删除*

尝试

mysql_query($sql);
echo mysql_error();

您应该出现错误

  

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   在第1行的'* from recencies'附近: