posting hidden value
Asked Answered
P

4

10

hey there, i have three pages: (1) bookingfacilities.php (2) booking_now.php (3) successfulbooking.php and they are link together.

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.

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" ?>"/>

i would greatly appreciate your help as my project is due tomorrow :(

Parsifal answered 25/1, 2011 at 15:8 Comment(0)
S
11

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.

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:

<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.

echo "<pre>";
print_r($_POST);
echo "</pre>";
Summertree answered 25/1, 2011 at 15:15 Comment(1)
is it right at the first page - booking facilities.php, i will need to add a hidden field function too?!Parsifal
L
9

Maybe a little late to the party but why don't you use sessions to store your data?

bookingfacilities.php

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

successfulbooking.php

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

Nobody will see this.

Lumberman answered 29/11, 2017 at 6:21 Comment(2)
Great idea, actually. There's no reason to use Get and Post data when you can simply use Sessions instead.Mathison
This is the best solution. I use session variables when I need data to persist through several pages. If not then you have to have inputs on every page to post the data again and again. Additionally, the variable used is "booking_now"... if it is NOW then why not use PHP's date() method. As in: $today = date("m-d-Y");Carroll
W
2

You have to use $_POST['date'] instead of $date if it's coming from a POST request ($_GET if it's a GET request).

Weinshienk answered 25/1, 2011 at 15:10 Comment(0)
G
1

I'm not sure what you just did there, but from what I can tell this is what you're asking for:

bookingfacilities.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
    $date = $_POST['date'];
    // add code here
?>

Not sure what you want to do with that third page(booking_now.php) too.

Guy answered 25/1, 2011 at 15:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.