post variable to another page without form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sectionLeader123
Forum Commoner
Posts: 31
Joined: Fri Oct 11, 2013 8:46 am

post variable to another page without form

Post by sectionLeader123 »

I have a form where the user submits data and when the form is submitted it runs the script info.php which is in the form action submits the data to the database. In the script I have used the last insert id function and set it to the variable $details. What I want to do is post the variable $details back to the form and echo it out on screen. When the user submits the form and info.php is executed it displays an alert box with the message Details Added and when the user clicks ok it displays another message saying "Do you want to close this tab?" and when the tab is closed I want the value for $details echoed on screen.

So far I have tried using sessions, so on the submission form I have:
session_start() at the top and to echo the variable I have:
<label>Job Reference Number:</label> <?php echo $_SESSION[$ref]; ?>

And in info.php I have session_start() at the top and to post the variable to the submission form I have:

$_SESSION[$details] = $ref;

Any suggestions would be greatly appreciated thanks
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: post variable to another page without form

Post by Christopher »

Please post your code.
(#10850)
priyankagound
Forum Commoner
Posts: 27
Joined: Thu Sep 19, 2013 2:53 am

Re: post variable to another page without form

Post by priyankagound »

Transferring variable VALUE can be accomplished with:
1) post form
2) in session
3) ajax call
you can do it with session by the following way:

session_start();
$_SESSION['user_profile'] = $user_profile['id'];

and use session variable every page you want the stored variables.
on every other pages you can retrieve the variable value like that

session_start();
$user_profile['id'] = $_SESSION['user_profile'];

Hope this helps.
sectionLeader123
Forum Commoner
Posts: 31
Joined: Fri Oct 11, 2013 8:46 am

Re: post variable to another page without form

Post by sectionLeader123 »

Got it appreciate the help
Post Reply