简体   繁体   English

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

[英]Sending form data to one page, then another?

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: 我有一个简单的表单,其中包含名称,电子邮件,注释等,可将自身输出到一个php页面,但是我想要一个链接将其发送到第二个页面,例如:

<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: 使用此代码转到第二页(second.php)并正确打印它:

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

Thank you, $name.

With the actual variable and not what was stored in $name. 使用实际变量而不是$ 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: 把它带到second.php,把它带到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. 只是看它是否可以从second.php获取相同的信息,但我认为它不是那样工作的。 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. 我觉得这是微不足道的,但是在我学习的过程中,我只是不太了解它。

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 在第二个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 = 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. 网站是无状态的,这意味着变量仅在服务器上持续几秒钟,然后呈现html并将其发送到客户端浏览器。 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). 1)使用隐藏的表单域并将其名称打印(使用php)到隐藏的表单域,以便在他们再次发布时将其保存(如果他们再次发布)。
2) Sessions 2)会议
3) cookies 3)饼干
4) Print it out in the url (ie page.php?name=".$name; ) 4)在网址中将其打印出来(即page.php?name =“。$ name;)

It all depends on how you get to your third page (From a link? A form? A php redirect?) 这完全取决于您如何进入第三页(从链接?表格?PHP重定向?)

You can store the name in the second page and again set the $_GET variable before the third page is called. 您可以将名称存储在第二页中,然后在调用第三页之前再次设置$ _GET变量。 This is because the variables are only valid for that particular request and they need to be set again when another request is made. 这是因为变量仅对特定请求有效,并且在发出另一个请求时需要再次设置它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM