首页 > 解决方案 > 根据单选按钮更新 MySQL 数据

问题描述

我现在面临一个挑战。

我有一个返回页面,如果我通过单选按钮选择了第一行,我想将我的订单历史记录表中的history_status从更改为。我这样做的原因是运行查询以仅显示history_status值。"DONE""RETURN PENDING""DONE"

以下是我正在使用的代码:

<?php
$db = mysqli_connect('localhost','root','','customercaremodule');
date_default_timezone_set('Asia/Kuala_Lumpur');
$FBdate = date("Y-m-d H:i:s");
$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'";
$result=mysqli_query($db,$sql);

$Cntsql = "SELECT count(return_id) AS total FROM retrn";
$res = mysqli_query($db,$Cntsql);
$value = mysqli_fetch_assoc($res);
$num = $value['total'];


if (isset($_POST['submitbuttonform']))
{

 $return_id = $num+1;
 $return_status = 'PENDING';
 $return_reason = $_POST['reasonselected'];
 $return_option = $_POST['returnoption'];
 $return_datetime = $FBdate;
 $history_id = $_POST['selectitemradio'];
 $history_status = "UPDATE orderhistory SET history_status = 'RETURN PENDING'";
 $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')";
 $sql = "INSERT INTO 'orderhistory'('history_status') VALUES ('$history_status')";
 $result=mysqli_query($db,$sql);

订单历史表

返回页面布局

标签: phpmysql

解决方案


从您的代码 $history_id = $_POST['selectitemradio']; 我假设您从页面中获取历史 ID。

因此,您可以在 where 子句中使用 history_id。现在只有选定的行将被更新。

UPDATE orderhistory SET history_status = 'RETURN PENDING' where history_id=$history_id


推荐阅读