I have two forms with the following names and properties:
1. register.php --- ----- action="register-exec.php" --- method="POST"
2. register-exec.php --- action="register-exec.php" --- method="POST"

After submitting the register.php, I used session in register-exec.php to store the value of the register.php for later use as follow:

$_SESSION['bookTitle'] = $_POST['txtBookTitle'];
$_SESSION['bookInfo'] = $_POST['txtBookInfo'];

Then after submitting the register-exec.php, I wanted to use those session variables, as follow:

if( isset($_POST['register-exec']) ){
     echo $bookTitle;
     echo $_SESSION['bookTitle'];

None of them work?
what is wrong ???

I hope you have session_start in all the required pages. If so, you can try to print out the session variables first, to see if it really has the values.
Try print_r($_SESSION); in all the pages and check if the session variables are really storing any values.

I stored the session in the register-exec.php, and in the same page I would like use those session variables, but when I use the echo and print_r, nothing display, I before Posting it is OK, but after that it is working.

I think u hav to use the seesion registrstion in your first page means in register.php .Then you can retrieve those session variables in the page where ever u want..


You have to use this code in register.php
Try this ...

$_SESSION['bookTitle'] = $_POST['txtBookTitle'];
$_SESSION['bookInfo'] = $_POST['txtBookInfo'];

Thanks for replying. Finally I used the <Input Hidden /> element of the form. and it worked well.

I will use the posted comments too.

This article has been dead for over six months. Start a new discussion instead.