在页面之间来回发送PHP变量 [英] Sending PHP variables back and forth between pages
问题描述
我创建了一个注册表单,它成功将其变量从注册页面(go-gold.php)传递到摘要/验证页面(go-gold-summary.php)。数据在第二页上正确显示。但是,我希望能够使用图像按钮返回注册页面,以防用户输入错误。回过头来,原始表单现在应该填入首次输入的数据。
问题是我无法将第二页的数据重新发送/返回到第一页。我的文本字段显示为空白。 我不想使用会话变量。
代码从整个页面截断。
注册页面(go-gold.php):
<?php
$ customer_name = $ _POST [ 'CUSTOMER_NAME'];
?>
< form action =go-gold-summary.phpmethod =post>
名称:< input type =textname =customer_nameid =customer_namevalue =<?php echo $ customer_name?> />
< input name =<?php echo $ customer_name?> type =hiddenid =<?php echo $ customer_name?>>
< / form>
摘要页面(go-gold-summary.php)
<?php
$ customer_name = $ _POST ['customer_name'];
?>
< form action =go-gold.phpmethod =post>
名称:<?php echo $ customer_name?> < input type =hiddenid =<?php echo $ customer_name?> name =<?php echo $ customer_name?>>
< INPUT TYPE =imagesrc =images / arrow_back.pngid =arrowalt =返回注册> (按钮返回注册页面)
< / form>
谢谢!
go-gold-summary.php 应该像这样改变。 <?php
$ customer_name = $ _POST ['customer_name'];
?>
< form action =go-gold.phpmethod =post>
名称:<?php echo $ customer_name?> < input type =hiddenvalue =<?php echo $ customer_name?> NAME = CUSTOMER_NAME >
< INPUT TYPE =submitsrc =images / arrow_back.pngid =arrowalt =返回注册> (按钮返回注册页面)
< / form>
注意我是如何改变这一行的
< input type =hiddenid =<?php echo $ customer_name?> name =<?php echo $ customer_name?>>
加入这个
< input type =hiddenvalue =<?php echo $ customer_name?> NAME = CUSTOMER_NAME >
$ _ POST是一个关联数组,当您提交表单时,它将像下面这样被填充: p>
$ _ POST [index] = value;
其中index
是文本字段name和 value
是文本字段值。
您在代码中错过了那个。只需使用我的代码进行更新即可使用
I've created a registration form that successfully passes its variables from the registration page (go-gold.php) to a summary/verfication page (go-gold-summary.php). The data appears correctly on the second page.
However, I want to able to use an image button to return back to the registration page, in case the user made an entry error. Going back, the original form should now be populated with the data that was first entered.
The problem is that I cannot re-send/return the data from the second page, back to the first. My text fields appear blank. I do NOT want to use Session variables.
The code is truncated from the entire page.
Registration Page (go-gold.php):
<?php
$customer_name = $_POST['customer_name'];
?>
<form action="go-gold-summary.php" method="post">
Name: <input type="text" name="customer_name" id="customer_name" value= "<?php echo $customer_name ?>" />
<input name="<?php echo $customer_name ?>" type="hidden" id="<?php echo $customer_name ?>">
</form>
Summary Page (go-gold-summary.php)
<?php
$customer_name = $_POST['customer_name'];
?>
<form action="go-gold.php" method="post">
Name: <?php echo $customer_name ?> <input type="hidden" id="<?php echo $customer_name ?>" name="<?php echo $customer_name ?>">
<INPUT TYPE="image" src="images/arrow_back.png" id="arrow" alt="Back to Registration"> (Button to go back to Registration Page)
</form>
Thanks!
go-gold-summary.php should be changed like this.
<?php
$customer_name = $_POST['customer_name'];
?>
<form action="go-gold.php" method="post">
Name: <?php echo $customer_name ?> <input type="hidden" value="<?php echo $customer_name ?>" name="customer_name">
<INPUT TYPE="submit" src="images/arrow_back.png" id="arrow" alt="Back to Registration"> (Button to go back to Registration Page)
</form>
notice how I've changed this line
<input type="hidden" id="<?php echo $customer_name ?>" name="<?php echo $customer_name ?>">
into this
<input type="hidden" value="<?php echo $customer_name ?>" name="customer_name">
$_POST is an associative array and as you submit the form it will be populated like this:
$_POST["index"] = value;
where "index"
is the text field "name" and value
is the text field value.
You've missed that one in your code. Just update it with my code and it will work
这篇关于在页面之间来回发送PHP变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!