简体   繁体   中英

Value not updating when form submitted(PHP, beginner level)

Why does this form not update the values that the items in my session? The session seems to keep track of the value fine, before the form tries to allow users to edit the value. Here's what I wrote out form submit:

<?php

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

        foreach($_POST['quantity'] as $key => $val) {

            if($val==0) {
                unset($_SESSION['Cart'][$key]);

            }else{
                $_SESSION['Cart'][$key]['quantity']=$val;
            }

        }


    }

?>

And here's the form:

<?php

            $sql="SELECT * FROM products where Product_ID IN (";

                    foreach($_SESSION['Cart'] as $id => $value){

                        $sql.=$id.",";
                        }
                        $sql=substr($sql, 0, -1).") ORDER BY Category ASC";
                        $query=mysql_query($sql);
                        $totalquantity=0;
                        while($row=mysql_fetch_array($query)){
                            $subtotal=$_SESSION['Cart'][$row['Product_ID']['quantity']]['quantity'];
                            $totalquantity+=$subtotal;
                        ?>
                            <tr>
                                <td><?php echo $row['Name'] ?></td>
                                <td><input = type="text" name="Quantity [<?php echo $row['Product_ID'] ?>]" size="5" value="<?php echo $_SESSION['Cart'][$row['Product_ID']['quantity']]['quantity'] ?>"/> </td>
                            </tr>
                        <?php
                        }


            ?>

And of course, the submit button is just

<button type="Submit" name="Submit">Update selection</button>

It looks like it should all work out properly, but it doesn't update.

Submit应该最有可能是“ submit”。在输入字段或$ _POST [“ Submit”]中更改它

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM