将动态文本框值保存到MySQL

时间:2015-05-30 08:56:14

标签: php phpmyadmin

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

(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;

    }

}

?>

1 个答案:

答案 0 :(得分:1)

你的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;

  }
}