duanhuai7532 2011-07-26 17:26
浏览 70
已采纳

PHP读取提交表单并将结果放入数组中

I have a form with dynamically created input fields - upon submitting it I would like to place all the generated data into an array using php.

An example of the html:-

<fieldset id="usp">
<input type="text" id="usp_1" name="usp_1" />
<input type="text" id="usp_2" name="usp_2" />
</fieldset>
<input type="hidden" id="uspTot" name="uspTot" />

input id=usp_1 and usp_2 were generated by Jquery on the fly - there can be any number of these inputs depending on the user so Jquery keeps a tally in the hidden field id=uspTot

When the form is posted I have tried to put the values of these input elements into a simple array using the following PHP code :-

$uspCount = $_POST["uspTot"];
for ($i=1; $i<=$uspCount; $i++)
 {
  $uspString[$i] = $_POST["usp_" + $i];
 };

It doesn't work of course! But I can't see why not?

Any pointers?

EDIT: this is the error code I receive:-

Notice: Undefined variable: POST in C:\Users\Andrew\Documents\Websites\example\html\submitbrief.php on line 21

EDIT 2:

This is the var_dump as requested by @Michael:-

array(36) { ["co_name"]=> string(11) "Daves autos" ["co_about"]=> string(16) "established 1969" ["co_id"]=> string(10) "Dave Smith" ["co_email"]=> string(21) "dave@davesautos.co.uk" ["co_phone"]=> string(11) "34435454545" ["usp_1"]=> string(9) "its great" ["usp_2"]=> string(9) "i love it" ["usp_3"]=> string(15) "its about car4s" ["uspTot"]=> string(1) "3" ["co_keyw_1"]=> string(0) "" ["co_keyw_2"]=> string(0) "" ["co_keyw_3"]=> string(0) "" ["co_keyw_4"]=> string(0) "" ["co_keyw_5"]=> string(0) "" ["co_compet"]=> string(0) "" ["ex_pos"]=> string(0) "" ["ex_neg"]=> string(0) "" ["ex_url"]=> string(0) "" ["pac_basic"]=> string(3) "yes" ["pac_cms"]=> string(2) "no" ["pac_eco"]=> string(2) "no" ["pac_ax"]=> string(4) "base" ["pac_ie6"]=> string(2) "no" ["pac_url"]=> string(0) "" ["pac_dom"]=> string(2) "no" ["pac_ins_1_url"]=> string(0) "" ["pac_ins_1_det"]=> string(0) "" ["pac_keyw_1"]=> string(0) "" ["pac_keyw_2"]=> string(0) "" ["pac_keyw_3"]=> string(0) "" ["pac_keyw_4"]=> string(0) "" ["pac_keyw_5"]=> string(0) "" ["pac_name"]=> string(0) "" ["pac_dem"]=> string(0) "" ["pac_gui"]=> string(0) "" ["pac_tex"]=> string(0) "" } 
  • 写回答

3条回答 默认 最新

  • douji0108 2011-07-26 17:34
    关注

    Try this in your for loop:

    $uspString[$i] = $_POST["usp_" . $i];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?