Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts

    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?

  • #2
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.
    Last edited by Mhtml; 01-31-2007 at 02:12 PM.
    Omnis mico antequam dominus Spookster!

  • #3
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts
    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

  • #4
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    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!

  • #5
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts
    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?

  • #6
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Have you:
    PHP Code:
    session_start() 
    ???
    Omnis mico antequam dominus Spookster!

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 315 Times in 307 Posts
    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.

  • #8
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts
    yeah, that's on the top of every page

  • #9
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Well that just leaves it down the $_POST['var'] being empty.
    Omnis mico antequam dominus Spookster!

  • #10
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts
    haha how stupid!
    That was the problem! I managed to fix it now! thank you both very much

  • #11
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    No problem.
    Omnis mico antequam dominus Spookster!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •