dongnong7524 2012-05-18 07:52
浏览 28
已采纳

来自具有相同名称的文本框的PHP请求名称

I have multiple textbox with same name, example :

<input type = "text" name = "addCart"/> 
<input type = "text" name = "addCart"/>
<input type = "text" name = "addCart"/>
<input type = "text" name = "addCart"/>

If I do a $_Request from php and I want to get the value inputted only from the first and fourth textbox, how can I do it? Thanks

  • 写回答

5条回答 默认 最新

  • douci1677 2012-05-18 07:54
    关注

    You can't. The last input box's value will overwrite all of the other ones' since they have the same name.

    What you could consider doing is using name="addCart[]"

    Then, $_REQUEST['addCart'] would be an array.

    Like:

    <input type="text" name="addCart[]" value="a">
    <input type="text" name="addCart[]" value="b">
    

    Then $_REQUEST['addCart'] (or $_POST or $_GET whichever you're using) would contain an array of two strings 'a' and 'b'.

    Edit: Just for completeness, I should note that this array is a normal array. Thus $_REQUEST['addCart'][x] where x is some integer index is valid as long as count($_REQUEST['addCart']) > x.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 根据动态演化博弈支付矩阵完成复制动态方程求解和演化相图分析等
  • ¥15 Prism框架ItemControl元素绑定ViewModel中的命令失败
  • ¥20 关于DAC输出1.000V对分辨率和精度的要求
  • ¥20 想写一个文件管理器,加载全部子文件夹后,要一级一级返回
  • ¥15 华为超融合部署环境下RedHat虚拟机分区扩容问题
  • ¥15 哪位能做百度地图导航触点播报?
  • ¥15 请问GPT语言模型怎么训练?
  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?