Walrus
Walrus

Reputation: 20444

Echo a PHP Session

I have a form that is supposed to store some of its data into a session. For the purpose of this example.

This information is then collected on another page.

<?php
session_start();
print_r($_SESSION['booking-form']);   ########### for debugging purposes  ###########

if ($_SESSION['booking-form']) {

    echo $_POST['GT_title'] 

    ?>
    <!DOCTYPE html>
    <html>
    <?php
}
elseif ($_SESSION['booking-form']) {
}?>
</html>

Now although the debug is working the echo is not working ie. echo S_POST['GT_title'].

  1. How do I echo the information on the second page.
  2. Can I echo it wherever I want it in the html (ie. in the middle of the body somewhere with
  3. On the first page some data in the form can be changed with options. This would need to update the session before the page is changed.

CLARIFICATION

For the purpose of a booking form. The user filled in a series of options that were then echo'd on the next page. At this point they need to log in so the form data must enter into a session. The session data should then be returned on a third page.

Upvotes: 0

Views: 5054

Answers (4)

Cedric
Cedric

Reputation: 5303

echo '<pre>';
print_r($_POST);
echo '</pre>';

Print it after your header. I hope this helps a little :)

Upvotes: 0

Dennis R&#246;ttger
Dennis R&#246;ttger

Reputation: 1985

For your echo question: Are you sure that GT_title is set? Posting the form on your previous page might help.

You can echo wherever you want, you can just put

<?=$varname?> 

anywhere in your html.

You can also update your session wherever you want.

$_SESSION['abc'] = value;

Upvotes: 0

Matt Asbury
Matt Asbury

Reputation: 5662

You can echo it wherever you want but if it doesn't exist or doesn't have a value then it might appear to be not working. To know for sure use var_dump($_POST['GT_title']);

Upvotes: 0

Ross
Ross

Reputation: 17967

1) what information? $_POST['GT_title'] would refer to a form element, presumably on the previous page. Does it exist? Is it filled in? what are you expecting?

2) You can echo where ever you like.

3) clarify? you can update a session with post values easily.

$_SESSION['foo'] = $_POST['bar']

your question isn't really that clear.

Upvotes: 2

Related Questions