dougu3988
dougu3988
采纳率100%
2012-02-27 03:30

将表单数据发送到一个页面,然后是另一个页面?

已采纳

I'm having a bit of trouble with this one, as basic as it may be. I have a simple form with name, email, comments, etc. that outputs itself to one php page, but I want to have a link that sends it to a second page, for example:

<label for="name">Name:</label><input type="text" name="name" size="20" />

Goes to a second page (second.php) with this code and prints it just fine:

print "<div>Thank you, $name.</p></div>";

But if I try to send $name to a third page (third.php) using similar code it shows up like this:

Thank you, $name.

With the actual variable and not what was stored in $name.

I feel like I'm missing one tiny little thing but I'm not sure what it is. I used this:

$name = $_POST['name'];

To bring it to second.php and this to bring it to third.php:

print 'Click <a href="third.php? name=' . $name . '">here</a> to proceed.';

Just to see if it would get the same information from second.php, but I don't think it works that way. Is there something else I should be doing on the third page? I have a feeling it's something incredibly insignificant but as I'm learning, I just can't quite get a grasp on it.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • douzhonglong3789 douzhonglong3789 9年前

    You can do it this way.

    when you declare

    $name = $_POST['name'];
    

    you can use in a header to pass this variable

    if(isset($_POST['btnname']))
    {
    header('Location: second.php?name='.$name);
    }
    

    The in your second php

    you can get it by this way

     Thank you, <php echo $_GET['name']; ?>
    

    Or if you want it to be available to all pages use session

    $_SESSION['name'] = $_POST['name'];
    

    =D

    点赞 评论 复制链接分享
  • douzongluo7542 douzongluo7542 9年前

    You can store the name in the second page and again set the $_GET variable before the third page is called. This is because the variables are only valid for that particular request and they need to be set again when another request is made.

    点赞 评论 复制链接分享
  • douhui0975 douhui0975 9年前

    Websites are stateless, which means that the variables only last for a few seconds on the server, then the html is rendered, and sent to the clients browser. The server memory is then freed up to serve other clients.

    You have a few options:
    1) Using a hidden form field and printing (with php) their name to the hidden form field so when they post again it gets saved (if they post again).
    2) Sessions
    3) cookies
    4) Print it out in the url (i.e. page.php?name=".$name; )

    It all depends on how you get to your third page (From a link? A form? A php redirect?)

    点赞 评论 复制链接分享
  • douhuangjie4503 douhuangjie4503 9年前

    you can try it using a hidden input

    <label for="name">Name:</label>
    <input type="hidden" name="name" value="<? echo $name; ?>" size="20" />
    
    点赞 评论 复制链接分享

为你推荐