Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-31-2007, 01:18 PM   PM User | #1
tribalmaniac
Regular Coder

 
Join Date: Sep 2006
Posts: 122
Thanks: 4
Thanked 2 Times in 2 Posts
tribalmaniac is an unknown quantity at this point
holding variables between pages

I have a registration form, with quite a bit of validation, if something doesnt match, then the php script will throw up an error with a "click here to go back"

When the user goes back using their browser or following the link, the variables of username, password etc etc dissapear causing the user to re-type everything, how can I stop this?
tribalmaniac is offline   Reply With Quote
Old 01-31-2007, 02:08 PM   PM User | #2
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
Either pass the variables with a query string or a cookie or session variable.

Example:
PHP Code:
<input type="text" name="user" value="<?php echo $_GET['user'?>" />
On the "click here to go back" link you'd have-
PHP Code:
<a href="url.php?user=<?php echo $_POST['user']; ?>">click here to go back</a>
Get it? Obviously you'd be best off doing it a bit more cleaner than that, but those are your options (query, cookie, session) and they're all similar to implement.

[edit:] If you really wanted, you *could* post them back as well with a bit of js.
__________________
Omnis mico antequam dominus Spookster!

Last edited by Mhtml; 01-31-2007 at 02:12 PM..
Mhtml is offline   Reply With Quote
Old 01-31-2007, 02:27 PM   PM User | #3
tribalmaniac
Regular Coder

 
Join Date: Sep 2006
Posts: 122
Thanks: 4
Thanked 2 Times in 2 Posts
tribalmaniac is an unknown quantity at this point
thanks for the fast reply!

The thing is, there is alot of information that will need to be moved around. The form uses "POST" to post to the next page, is there a way of transferring the data without the user knowing (without using sessions or cookies?) SOrry if you've already answered this

Matt
tribalmaniac is offline   Reply With Quote
Old 01-31-2007, 02:31 PM   PM User | #4
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
Well, you can store the info somewhere.. But you're still going to need a way to associate that user with the data.. either sessions or a cookie..
__________________
Omnis mico antequam dominus Spookster!
Mhtml is offline   Reply With Quote
Old 01-31-2007, 02:47 PM   PM User | #5
tribalmaniac
Regular Coder

 
Join Date: Sep 2006
Posts: 122
Thanks: 4
Thanked 2 Times in 2 Posts
tribalmaniac is an unknown quantity at this point
right ok thanks

Im sorry if this is really stupid, but when i post the information, I assign the information to the session like this:
PHP Code:
$_SESSION['usernamestored'] = $_POST['username']; 
and then on the first page (the one they entered the info on) I enter this:

PHP Code:
echo('<input type="text" class="smallform" name="username" value="'.$_SESSION['usernamestored'].'" />'); 
but the input box appears blank?
tribalmaniac is offline   Reply With Quote
Old 01-31-2007, 02:52 PM   PM User | #6
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
Have you:
PHP Code:
session_start() 
???
__________________
Omnis mico antequam dominus Spookster!
Mhtml is offline   Reply With Quote
Old 01-31-2007, 02:55 PM   PM User | #7
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,711
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
Do you have a session_start(); php statement as the first thing on every page that references any $_SESSION variable?
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
CFMaBiSmAd is offline   Reply With Quote
Old 01-31-2007, 03:04 PM   PM User | #8
tribalmaniac
Regular Coder

 
Join Date: Sep 2006
Posts: 122
Thanks: 4
Thanked 2 Times in 2 Posts
tribalmaniac is an unknown quantity at this point
yeah, that's on the top of every page
tribalmaniac is offline   Reply With Quote
Old 01-31-2007, 03:07 PM   PM User | #9
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
Well that just leaves it down the $_POST['var'] being empty.
__________________
Omnis mico antequam dominus Spookster!
Mhtml is offline   Reply With Quote
Old 01-31-2007, 03:41 PM   PM User | #10
tribalmaniac
Regular Coder

 
Join Date: Sep 2006
Posts: 122
Thanks: 4
Thanked 2 Times in 2 Posts
tribalmaniac is an unknown quantity at this point
haha how stupid!
That was the problem! I managed to fix it now! thank you both very much
tribalmaniac is offline   Reply With Quote
Old 01-31-2007, 04:05 PM   PM User | #11
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
No problem.
__________________
Omnis mico antequam dominus Spookster!
Mhtml is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:05 AM.


Advertisement
Log in to turn off these ads.