如何使用php删除/删除mySQL中的特定表行?

时间:2012-07-31 05:37:39

标签: php mysql

我已经有了这段代码:

<?php
if ($quantity == 0){
$prd_name = " ";
$colors = " ";
$sizes = " ";
$quantity = " ";
$price = " ";
$TIP = " ";
$TPA = " ";
$cost = " ";
$amount = " ";
$query ="DELETE FROM orders WHERE quantity='0'";
}
?>

但它仍然会创建一个表行。

我想要做的是当输入的数量为0时,表行将被删除。请耐心等待我,我是php和mySQL编码的新手。

3 个答案:

答案 0 :(得分:1)

您忘记执行查询。它应该是

$query = mysql_query("DELETE FROM orders WHERE quantity='0'");

答案 1 :(得分:0)

<?php
    if($quantity==0)
     {
       $query="Delete from orders where quantity=0";
       mysql_query($query);
      }
 ?>

答案 2 :(得分:0)

通过将引号移至 0 运行查询如果是数字

<?php
    if($quantity==0)
     {
       $query = "DELETE FROM orders WHERE quantity = 0 ";
       mysql_query($query);
      }
 ?>