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 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突