如何将选定的文本值从数组会话获取到另一个页面


how get the selected text value from array session to another page

这是cart.php:

   foreach($_SESSION['cart'] as $k) {   
    <form class ="align-left"name="form1" method="post" action="cartqty.php">
      <tr>
      <td><p><?php $k['products_title']; ?></p></td>
      <td><input type="text" name="product_qty[]" value=""/></td>
      <td><input type="hidden" name="product_code" value="<?php $k['products_id']; ?>"/>   </td>
      <td><?php echo number_format($k['price'],2); ?></td>
        </tr>
       <?php
     <input type="submit" name="submit" value="update">                 
    }
    ?>
    </table>
    </form>

这是cartty .php:

session_start();
$product_code   = $_POST["product_code"];
$product_qty    = $_POST["product_qty"];

如何获得输入文本数量的选择值,以便我可以相应地更新会话值,我总是获得product_qty数组的最后一个值。请求帮助! !

您需要在foreach块内关闭form标签,如:

foreach($_SESSION['cart'] as $k) {   
<form class ="align-left"name="form1" method="post" action="cartqty.php">
  <tr>
  <td><p><?php $k['products_title']; ?></p></td>
  <td><input type="text" name="product_qty[]" value=""/></td>
  <td><input type="hidden" name="product_code" value="<?php $k['products_id']; ?>"/>   </td>
  <td><?php echo number_format($k['price'],2); ?></td>
    </tr>
   <?php
 <input type="submit" name="submit" value="update">                 
 </form>
}
?>
</table>