php 发布隐藏值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4795072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
posting hidden value
提问by jocelync
hey there, i have three pages: (1) bookingfacilities.php (2) booking_now.php (3) successfulbooking.php and they are link together.
嘿,我有三个页面:(1)bookingfacilities.php(2)booking_now.php(3)successbooking.php,它们链接在一起。
i want to pass data from bookingfacilities.php to successfulbooking.php by using hidden field/value. however, my data doesn't get print out in successfulbooking.php.
我想通过使用隐藏字段/值将数据从bookingfacilities.php 传递到successbooking.php。但是,我的数据没有在successbooking.php 中打印出来。
here are my codes:
这是我的代码:
from 'booking_now.php':
$date="$day-$month-$year";
from 'successfulbooking.php';
<input type="hidden" name="date" id="hiddenField" value="<?php print "$date" ?>"/>
来自“booking_now.php”:
$date="$day-$month-$year";
来自'successfulbooking.php';
<input type="hidden" name="date" id="hiddenField" value="<?php print "$date" ?>"/>
i would greatly appreciate your help as my project is due tomorrow :(
我将非常感谢您的帮助,因为我的项目明天到期:(
回答by Michael Irigoyen
You should never assume register_global_variables
is turned on. Even if it is, it's deprecated and you should never use it that way.
您永远不应该假设register_global_variables
已打开。即使是这样,它也已被弃用,您永远不应该那样使用它。
Refer directly to the $_POST
or $_GET
variables. Most likely your form is POSTing, so you'd want your code to look something along the lines of this:
直接参考$_POST
或$_GET
变量。很可能您的表单正在发布,因此您希望您的代码看起来像这样:
<input type="hidden" name="date" id="hiddenField" value="<?php echo $_POST['date'] ?>" />
If this doesn't work for you right away, print out the $_POST
or $_GET
variable on the page that would have the hidden form field and determine exactly what you want and refer to it.
如果这对您不起作用,请在页面上打印出包含隐藏表单字段的$_POST
or$_GET
变量,并准确确定您想要什么并引用它。
echo "<pre>";
print_r($_POST);
echo "</pre>";
回答by Niels
Maybe a little late to the party but why don't you use sessions to store your data?
也许聚会有点晚了,但为什么不使用会话来存储数据呢?
bookingfacilities.php
预订设施.php
session_start();
$_SESSION['form_date'] = $date;
successfulbooking.php
成功预订.php
session_start();
$date = $_SESSION['form_date'];
Nobody will see this.
没有人会看到这一点。
回答by ThiefMaster
You have to use $_POST['date']
instead of $date
if it's coming from a POST request ($_GET if it's a GET request).
如果它来自 POST 请求(如果是 GET 请求,则为 $_GET),您必须使用它来$_POST['date']
代替$date
。
回答by rgin
I'm not sure what you just did there, but from what I can tell this is what you're asking for:
我不确定你刚刚在那里做了什么,但据我所知,这就是你的要求:
bookingfacilities.php
预订设施.php
<form action="successfulbooking.php" method="post">
<input type="hidden" name="date" value="<?php echo $date; ?>">
<input type="submit" value="Submit Form">
</form>
successfulbooking.php
成功预订.php
<?php
$date = $_POST['date'];
// add code here
?>
Not sure what you want to do with that third page(booking_now.php) too.
不确定你想用第三页(booking_now.php)做什么。