dqajyxqem115006813 2015-04-28 20:11
浏览 32
已采纳

$ _POST []的范围,试图访问$ _POST []变量,得到未定义的索引错误

I have these two forms that submits to different blocks of the same script. i am unable to access variable of one block in other, though both variables are in same script.

html form :(1.php)

<html>
  <form method="POST" action="2.php" enctype="multipart/form-data">
    </br>
    Choose a user name:</font>
    <input type="text" name="username">
    <input type="submit" name="submit" value="Save and Proceed">
  </form>
</html>

2.php:

 <?php
    $name=$_POST['username'];
    if ((isset($_POST['username'])) && ($_POST['submit'] == 'Save and Proceed'))
    {
        $name=$_POST['username'];
        echo $name;
        if($name=='azra')
        {
        ?>
        <html>
          <form method="POST" action="2.php" enctype="multipart/form-data"></br>
            enter age:</font>
            <input type="text" name="age">
            <input type="submit"  name="submit" value="done">
          </form>
        </html>
        <?php
        }
    }

    if((isset($_POST['age'])) && ($_POST['submit'] == 'done'))
    {
        $age=$_POST['age'];
        echo $age;
        if($age==25)
        {
            echo "hi" .$name;
            echo "your age is ". $age;
            echo"you are eligible";
        }
    }   

  ?>

How do I access $_POST['username'] in the code following the html form in the same script? Thank you in advance.

  • 写回答

2条回答 默认 最新

  • dongqiang4986 2015-04-28 20:16
    关注

    If I understand well you want to pass username twice. Than you can use hidden input, which is not visible (only transports data):

    <input type="hidden" name="username" value="<?php echo $_POST['username']; ?>" />
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输