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

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

问题描述:

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.

我对这个问题有点麻烦,尽管它很基本。 我有一个简单的表单,名称,电子邮件,评论等,将自己输出到一个php页面,但我希望有一个链接将其发送到第二页,例如: p>

 &lt; label for =“name”&gt;名称:&lt; / label&gt;&lt; input type =“text”name =“name”size =“20”/&gt; 
  code>   pre> 
 
 

使用此代码转到第二页(second.php)并打印出来就好了: p>

  print“&lt; div&gt;谢谢 ,$ name。&lt; / p&gt;&lt; / div&gt;“; 
  code>  pre> 
 
 

但是如果我尝试将$ name发送到第三页(third.php) 使用类似的代码,它显示如下: p>

 谢谢,$ name。
  code>  pre> 
 
 

使用实际变量 而不是存储在$ name中的东西。 p>

我觉得我错过了一个小小的东西,但我不确定它是什么。 我用过这个: p>

  $ name = $ _POST ['name']; 
  code>  pre> 
 
 

将它带到 second.php和这将把它带到third.php: p>

  print'Click&lt; a href =“third.php?name ='。$ name。'”&gt  ;这里&lt; / A&GT; 继续。'; 
  code>  pre> 
 
 

只是为了看看它是否会从second.php获得相同的信息,但我不认为它是这样的。 我还应该在第三页上做些什么吗? 我觉得这是一件非常微不足道的事情,但正如我在学习的那样,我无法理解它。 p> div>

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

you can try it using a hidden input

<label for="name">Name:</label>
<input type="hidden" name="name" value="<? echo $name; ?>" size="20" />

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?)

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.