dpw70180 2013-07-24 15:04
浏览 42
已采纳

具有相同名称的php多个下拉菜单无法获取值

okay, im new in this site also new in php and can't get the logic on this,

i have a product page that shows the name, quantity and an add to cart button in each row of product

i made this just cutted of some code

    while($showProducts = mysql_fetch_array($products))
            {
            $currenQuantity = $showProducts['current_quantity'];
            $prodid = $showProducts['product_id'];
    echo"<select name='quan'>";

                for ($x=0;$x<=$currenQuantity;$x++)
            {
                if($currenQuantity != 0)
                {
                echo "<option value=$x> $x </option>";
                }
            }
     echo"</select><br/>";
     }

now the problem is every time i tried to get the value by using $_POST['quan'] the value that i always get is the default value 1 even i select a different value of quantity of a certain product, and i'm blanked with ideas.

  • 写回答

3条回答 默认 最新

  • dousong9729 2013-07-24 15:12
    关注

    You can't use the same name for an input/select field in a form. You have to specify a diffrent name or create an indexed array:

    <select name="quan[$prodid]">
    

    You can acces it via

    $_POST['quan'][$prodid]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?