wpdb-> insert产生重复项

时间:2018-10-04 10:59:26

标签: php mysql wordpress

我正在尝试在页面上创建一个按钮,以从数据库中打印出数据,然后可以按2个不同的按钮,一个按钮将其从数据库中删除,另一个按钮将其插入数据库中的另一个表中并删除数据库中的数据,但它一直将其两次插入到新表中,我不知道为什么,这里打印出数据和会话变量+按钮:

if(!isset($_POST['orderby'])) {
  foreach ($requests as $row) {
    echo "<div class='requests'>" . "<li class='refunds'>" . "Palauttajan nimi: ".
    $row['customer_name'] . "</br>" ."Palautettavat tuotteet: ".$row['product_name']."<br> "."Määrä: ".
    $row['product_qty'] . " "
    . "<br>Kommentti: " . $row['comment'] . "<br> " . "Hinta: " . $row['refund_total'] . "€ " .
    "<br>" . "Päivämäärä: " . $row['request_date'] . " " .
    "<a class='right' href='admin-page?deleteid=" . $row['request_id'] . "'>Hylkää</a></li>" .
    "<li class='refundaccepts'><a href='admin-page?acceptid=" . $row['request_id']
    . "'>Hyväksy</a></li>" . "</div>";
    $_SESSION['custname'] = $row['customer_name'];
    $_SESSION['prodname'] = $row['product_name'];
    }
  } else {
    foreach ($pergele as $row) {
      echo "<div class='requests'>" . "<li class='refunds2'>" . "Palauttajan nimi: ".
      $row['customer_name'] . "</br>" ."Palautettavat tuotteet: ".$row['product_name']."<br> "."Määrä: ".
      $row['product_qty'] . " "
      . "<br>Kommentti: " . $row['comment'] . "<br> " . "Hinta: " . $row['refund_total'] . "€ " .
      "<br>" . "Päivämäärä: " . $row['request_date'] . " " .
      "<a class='right' href='admin-page?deleteid=" . $row['request_id'] . "'>Hylkää</a></li>" .
      "<li class='refundaccepts'><a href='admin-page?acceptid=" . $row['request_id']
      . "'>Hyväksy</a></li>" . "</div>";
      $_SESSION['custname'] = $row['customer_name'];
      $_SESSION['prodname'] = $row['product_name'];
    }
  }

这应该将其插入数据库一次,然后从旧表中删除数据:

 if(isset($_GET['acceptid'])) {
   $accept = $_GET['acceptid'];
   $custname = $_SESSION['custname'];
   $prodname = $_SESSION['prodname'];
   /* Query to do whatever here */
   $wpdb->insert("wp_acceptedrequests", [
      "customer_name" => "$custname",
      "name_product" => "$prodname",
      "date" => date("Y/m/d/G:i:sa") ,
  ]);
  $wpdb->query("DELETE FROM wp_refundrequests WHERE request_id = $accept");

  }

是什么让他们插入两次,如何防止它插入?

1 个答案:

答案 0 :(得分:0)

我只是遇到了类似的情况,其中$ wpdb在重复的位置插入。 就我而言,如果我通过了身份验证并且浏览器检查器处于打开状态,这是正在发生的事情。