dsiy62758 2014-08-04 04:46
浏览 83
已采纳

将表单数据放入PHP数组中

I have this form

  <form action = "put the data to a single PHP array" method="post">
    <input name="a" type="text" />
    <input name="b" type="text" />
    <input name="c" type="text" /> 
    <input name="d" type="text" /> 
    <input type="button">
  </form>

the condition is that I want to put the data into a PHP array when the user filled the form and click the submit button. the data should be order the way the text input fields are arranged. how can I do that?

Pls help me with the code. thanks!

  • 写回答

2条回答 默认 最新

  • douyue7536 2014-08-04 04:58
    关注

    Change the name of your inputs like this:

    <form action = "put the data to a single PHP array" method="post">
        <input name="a[]" type="text" />
        <input name="a[]" type="text" />
        <input name="a[]" type="text" /> 
        <input name="a[]" type="text" /> 
        <input type="button"/>
    </form>
    

    You can then retrieve the array as follows:

    $values = $_POST['a'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • douhang1913 2014-08-04 05:29
    关注

    hi Jonas if you need the values to be passed as an array then you can use

    <form action = "submit the data to a PHP array" method="post">
         <input name="ar[]" type="text" />
         <input name="ar[]" type="text" />
         <input name="ar[]" type="text" /> 
         <input name="ar[]" type="text" /> 
         <input type="button">
    </form>
    

    while accessing you can use

    $ar=$_POST['ar'];
    $size=sizeof($ar);
        for($i=0;$i<$size;$i++)
        {
          echo "$ar[$i]";
        }
    

    Generally we use this type of array passing when we use multiple checkboxes value to be passed

    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下simulink中S函数相关问题
  • ¥15 Hadoop中eclipse运行问题
  • ¥15 在二层网络中,掩码存在包含关系即可通信
  • ¥15 端口转发器解析失败不知道电脑设置了啥
  • ¥15 Latex算法流程图行号自定义
  • ¥15 关于#python#的问题:我在自己的电脑上运行起来总是报错,希望能给我一个详细的教程,(开发工具-github)
  • ¥40 基于51单片机实现球赛计分器功能
  • ¥15 cs2游戏画面卡住,应用程序sid与指挥者sid不匹配
  • ¥15 实验七:Pandas要有实验截图和代码
  • ¥15 TypeError: Make sure that the iterable only contains strings.