dpq39825 2019-06-25 13:12
浏览 63
已采纳

从链接的textareas的$ _POST数据中获取id

Trying to link two fields on a POST by getting the ID.

Each 'songfld' has a unique number as below. The textarea is linked on that number.

The form fields:

<input type="text" name="songfld[901]" value="">
<textarea name="data[901][name]" id="txt-901" rows="2" cols="80"></textarea>

<input type="text" name="songfld[902]" value="">
<textarea name="data[902][name]" id="txt-902" rows="2" cols="80"></textarea>

And trying to get the 901 & 902 ID's here:

foreach($_POST['songfld'] as $val){
    $val is the value from input
    $id = $_POST['songfld'][0];     // the number in each name="songfld[X]"
    $namefld = $_POST['data'][$id]['name']; // gives the value from textarea

    echo "<P>$id $idfld $namefld";
}

Of course the value passes, but I'd like to have that unique number from each post as well.

hope someone knows this trick.

  • 写回答

3条回答 默认 最新

  • duandeng2265 2019-06-25 13:21
    关注

    Inspect your data like this:

    echo "<pre>";
    print_r($_POST);
    echo "</pre>";
    exit;
    

    Also try:

    echo "<pre>";
    print_r($_POST['songfld']);
    echo "</pre>";
    exit;
    

    You'll see what is exactly in the arrays.

    foreach($_POST['songfld'] as $name => $val){
      ...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度