从mysqli查询中的多个表中删除行

时间:2017-02-05 20:08:55

标签: php mysqli

如果所有表都具有共同值,如何从多个表中删除 这里使用了代码,但没有工作

 <?php

include_once("config.php");

$order_no = $_REQUEST['id'];
    $order_date = $_REQUEST['date'];


$conn->query("DELETE FROM `orders` WHERE `date`='$order_date' and `order_no`='$order_no';
DELETE FROM `customer_order` WHERE `order_date`='$order_date' and `order_no`='$order_no';
DELETE FROM `driver_order` WHERE `order_date`='$order_date' and `order_no`='$order_no';");
header('location:index.php');

?>

2 个答案:

答案 0 :(得分:0)

您有一个$date变量,但在查询中使用$order_date

请注意,这不是安全的方法。寻找SQL注入。

答案 1 :(得分:0)

<强>解决

<?php

 include_once("config.php");

    $order_no = $_REQUEST['id'];
    $order_date = $_REQUEST['date'];


 $conn->query("DELETE `orders`,`customer_order`,`driver_order` 
 FROM `orders`,`customer_order`,`driver_order`
  WHERE `orders`.`date`='$order_date' and `orders`.`order_no`='$order_no' AND
`customer_order`.`order_date`='$order_date' and `customer_order`.`order_no`='$order_no' AND

driver_orderorder_date = '$ order_date的'      和driver_orderorder_no ='$ order_no';“);       头( '位置:的index.php');

     ?>