保存动态文本框值到MySQL


Saving dynamic text box values to MySQL

我想从购物车文本框中保存动态文本框中的数据。我的代码如下。我不能保存。

(32B到40B为文本框名和表列名)

global $con;    
if(isset($_POST['update_cart'])){
    foreach($_POST['remove/update'] as $remove/update_id){
    $size_1 = $_POST['32B'];
    $size_2 = $_POST['34B'];
    $size_3 = $_POST['34C'];
    $size_4 = $_POST['36B'];
    $size_5 = $_POST['36C'];
    $size_6 = $_POST['38B'];
    $size_7 = $_POST['38C'];
    $size_8 = $_POST['40B'];
    $update_qty = "update cart set 32B='$size_1', 34B='$size_2', 34C='$size_3', 36B='$size_4', 36C='$size_5', 38B='$size_6', 38C='$size_7', 40B='$size_8'";
    mysqli_query($con, $update_qty);
    echo $update_qty;
    }
}
?>

你的foreach看起来有点不对劲。没有看到完整的形式,我不确定$_POST['remove/update']是正确的,但如果是,这应该工作。

global $con;    
if(isset($_POST['update_cart'])){
  foreach($_POST['remove'] as $update){
    $size_1 = $update['32B'];
    $size_2 = $update['34B'];
    $size_3 = $update['34C'];
    $size_4 = $update['36B'];
    $size_5 = $update['36C'];
    $size_6 = $update['38B'];
    $size_7 = $update['38C'];
    $size_8 = $update['40B'];
    $update_qty = "update cart set 32B='$size_1', 34B='$size_2', 34C='$size_3', 36B='$size_4', 36C='$size_5', 38B='$size_6', 38C='$size_7', 40B='$size_8'";
    mysqli_query($con, $update_qty);

    echo $update_qty;
  }
}