基于单选按钮更新mysql数据

nwsw7zdq  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(340)

我现在正面临一个挑战。
我有一个返回页,如果我通过单选按钮选择了第一行,我想改变我的订单历史表中的历史状态 "DONE""RETURN PENDING" . 我这样做的原因是运行一个查询,只显示历史记录和状态值 "DONE" .
下面是我正在使用的代码:

  1. <?php
  2. $db = mysqli_connect('localhost','root','','customercaremodule');
  3. date_default_timezone_set('Asia/Kuala_Lumpur');
  4. $FBdate = date("Y-m-d H:i:s");
  5. $sql = "SELECT p.product_id ,p.product_name , p.price, p.product_description, o.history_id ,o.qty , o.subtotal, o.history_datetime , o.history_status FROM product p, orderhistory o where o.product_id = p.product_id AND o.history_status = 'DONE'";
  6. $result=mysqli_query($db,$sql);
  7. $Cntsql = "SELECT count(return_id) AS total FROM retrn";
  8. $res = mysqli_query($db,$Cntsql);
  9. $value = mysqli_fetch_assoc($res);
  10. $num = $value['total'];
  11. if (isset($_POST['submitbuttonform']))
  12. {
  13. $return_id = $num+1;
  14. $return_status = 'PENDING';
  15. $return_reason = $_POST['reasonselected'];
  16. $return_option = $_POST['returnoption'];
  17. $return_datetime = $FBdate;
  18. $history_id = $_POST['selectitemradio'];
  19. $history_status = "UPDATE orderhistory SET history_status = 'RETURN PENDING'";
  20. $sql = "INSERT INTO `retrn`(`return_id`, `return_status`, `return_reason`, `return_option`, `return_datetime`, `history_id`) VALUES ('$return_id','$return_status','$return_reason','$return_option','$return_datetime','$history_id')";
  21. $sql = "INSERT INTO 'orderhistory'('history_status') VALUES ('$history_status')";
  22. $result=mysqli_query($db,$sql);


订单历史记录表

返回页布局

vzgqcmou

vzgqcmou1#

从代码$history\u id=$\u post['selectitemroid'];我想你是从页面上得到历史记录的。
所以可以在where子句中使用history\u id。现在只更新选定的行。
update orderhistory set history\u status='return pending'其中history\u id=$history\u id

相关问题