dqajyxqem115006813 2015-04-28 12: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 12: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条)
编辑
预览

报告相同问题?