#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    Northern Illinois
    Posts
    171
    Rep Power
    14

    Question Carry a $POST variable from page to page in a hidden field


    One would think that this should be fairly simple process but I can't seem to find the correct code.

    I'm trying to carry a POST variable from page to page with a hidden field. The code that I'm attaching is on a page that already carried in the variable "$_POST['selectedCourseName']" from a prior form. There are several other form fields on this page. To keep it simple, I will only post the hidden field section, here it is:

    <form action="<?php echo $PHP_SELF ?>" method="POST">
    <input type="hidden" name="action" value="form3">
    <input type="hidden" name="selectedCourseName" value="<?php echo $_POST['selectedCourseName'] ?>">
    <br>

    (left out several more form fields that are in a table)
    <input name="submit" type="submit"></form>

    Since the variable has already been carried in via post, my thought is that I should be able to carry it to the next page with this hidden field but the variable "$selectedCourseName", is passed with nothing in it. My code (value="<?php echo $_POST['selectedCourseName'] ?>) is not picking up the $POST variable that was passed in from the prior page and I don't know why.

    Can anyone shed some light on this?
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2001
    Posts
    606
    Rep Power
    33
    On the page you are going to do a
    PHP Code:
    print_r($_POST)
    //or
    print_r($_REQUEST
    It should show all values passed
    from what I can tell at a quick glance it should work.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    Northern Illinois
    Posts
    171
    Rep Power
    14
    Thanks for your help menator,

    After looking at all the variables I discovered that I had registered $SESSION[selectedCourseName] earlier and forgot. The variable was there it was just picked up by the SESSION.

    Why do I always have to shoot myself in the foot It hurts!


    Thanks again
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2001
    Posts
    606
    Rep Power
    33
    Glad I could help
  8. #5
  9. No Profile Picture
    loves google.
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2001
    Location
    Pacific Northwest
    Posts
    645
    Rep Power
    31
    Unrelated note: If you're going to use $_POST (superglobals) then you may as well use $_SERVER['PHP_SELF'] because $PHP_SELF only exists if the PHP directive register_globals is on. (assuming you didn't create it yourself)

IMN logo majestic logo threadwatch logo seochat tools logo