Php 发布隐藏值

Php 发布隐藏值,php,forms,hidden,Php,Forms,Hidden,嘿,那里, 我有三页: (1) bookingfacilities.php (2) booking_now.php (3) successfulbooking.php 它们是联系在一起的 我想使用隐藏字段/值将数据从bookingfacilities.php传递到successfulbooking.php。但是,我的数据没有在successfulbooking.php中打印出来 这是我的密码: 从“booking_now.php”开始: $date=“$day-$month-$year” 来自

嘿,那里, 我有三页: (1) bookingfacilities.php (2) booking_now.php (3) successfulbooking.php 它们是联系在一起的

我想使用隐藏字段/值将数据从bookingfacilities.php传递到successfulbooking.php。但是,我的数据没有在successfulbooking.php中打印出来

这是我的密码:

  • 从“booking_now.php”开始:
    $date=“$day-$month-$year”

  • 来自“successfulbooking.php”;
    如果来自POST请求,则必须使用
    $\u POST['date']
    而不是
    $date
    (如果是GET请求,则使用$\u GET)。

    决不能假设启用了
    注册全局变量。即使是这样,它也被弃用了,您永远不应该以这种方式使用它

    直接参考
    $\u POST
    $\u GET
    变量。您的表单很可能正在发布,因此您希望您的代码看起来像这样:

    <input type="hidden" name="date" id="hiddenField" value="<?php echo $_POST['date'] ?>" />
    
    ";
    我不确定你刚才在那里做了什么,但从我可以看出这就是你想要的:

    bookingfacilities.php

    <?php
        $date = $_POST['date'];
        // add code here
    ?>
    
    session_start();
    $date = $_SESSION['form_date']; 
    
    
    

    我也不知道你想用第三个页面(booking_now.php)做什么。

    可能会晚一点到派对,但为什么不使用会话来存储数据呢

    bookingfacilities.php

    <?php
        $date = $_POST['date'];
        // add code here
    ?>
    
    session_start();
    $date = $_SESSION['form_date']; 
    
    successfulbooking.php

    session_start();
    $_SESSION['form_date'] = $date;
    

    没有人会看到这一点。

    在第一页-booking facilities.php,是否正确,我还需要添加一个隐藏字段函数?!事实上,这是一个好主意。当您可以简单地使用会话时,没有理由使用Get和Post数据。这是最好的解决方案。当我需要数据在多个页面中持久化时,我使用会话变量。如果不是,则你必须在每一页上输入一次又一次地发布数据。此外,使用的变量是“booking_now”…如果是现在,为什么不使用PHP的date()方法。如:$today=date(“m-d-Y”);