dongshi4078 2019-04-22 04:57
浏览 29

如何从输入名称发布数组值

i want to pass an array value from input name that generated from an array. i can view $_POST if i manually define on script.

   $stmt    = $db->prepare($sql); 
    $stmt->execute();
    $i = 0;
    while ($row = $stmt->fetch())
    {

        $id=strtoupper($row["id"]);
        $nama=strtoupper($row["nama"]);
        $sn=strtoupper($row["sn"]);
        $kewpa=strtoupper($row["kewpa"]);?>



        <form method="post" action="kewpaupdate.php"><tr>
        <td><input type="text" name="id[<?php echo $i;?>]" value=<?php echo $id;?>></td>
        <td></td>
        <td></td>
        <td><input type="text" name="kewpa[<?php echo $i;?>]" value=<?php echo $kewpa;?>></td>
        <td align="center"><input type="submit" value="submit"></td>

        </tr></form>
        <?php ++$i;
    ?>
     </tbody>
    </table>

<?php

$w = $_POST['id'];
$r = $_POST['kewpa'];

echo $w;
echo "<br>";
echo $r;
?>

how to display array value that choose from submit button.

  • 写回答

1条回答 默认 最新

  • dongmou2389 2019-04-22 05:02
    关注

    You need to do 2 things:

    1) As you are printing the $_POSTed data on the page itself, you need to submit the form to same page.

    Please change <form> action to blank.

    Changed form action code:

    <form method="post" action="">

    This will submit the form to same page.

    2) As your input has name of type array, you can't just print it with echo or print().

    These are used for printing strings.

    You need to use print_r().

    So, please use:

    echo '<pre>';
    print_r($_POST['id']);
    echo '<pre>';
    

    You will get an array, same for the other field.

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?