duansen6750 2017-03-16 14:36
浏览 6

这怎么办? [关闭]

I know this code doesn't work. I want to pass $var1, $var2, and name to next.php. How can I do that?

<?php
    $var1="test1";
    $var2="test2";
?>

<form method="get">
    <input type="text" name="name">
    <a <?php echo "href='next.php?test1=".$var1."&test2=".$var2."'"?> >next</a>
</form>

in next.php

$var1=$_GET['name'];
$var2=$_GET['test1'];
$var3=$_GET['test2'];
  • 写回答

2条回答 默认 最新

  • douqie1884 2017-03-16 14:38
    关注

    You can pass the values as hidden inputs so that your other values in the form would still be passed with it.

    <form action="next.php">
        <input type="text" name="name">
        <input type="hidden" name="test1" value="<?php echo $var1; ?>">
        <input type="hidden" name="test2" value="<?php echo $var2; ?>">
        <button type="submit">Submit</button>
    </form>
    

    Then in your next.php, you will receive everything in the $_GET.

    Example, if the user fills in Foo as the name and click on submit, then you will receive the following in your next.php:

    var_dump($_GET)

    array(3) {
        ["name"]=> string(3) "Foo"
        ["test1"]=> string(5) "test1"
        ["test2"]=> string(5) "test2"
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度