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 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题