SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    Shelby, NC USA
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sessions aren't working

    Please refer to the code below:
    PHP Code:
    page1

    <form action="page2.php" method="post" name="form">
    <
    input class="input" id="input" type="text" name="name" size="30" />
    </
    form>

    page2

    session_start
    ();
    $_SESSION['name'] = $name;

    page3

    session_start
    ();
    echo 
    $name
    Here's the problem- on page3 echo name produces nothing. In fact, I can't even echo the name on page2. Have played with this for hours and can't seem to find the problem. I'm sure I'm overlooking something simple- can anyone tell me what? Thanks!
    Earl Parker II

  2. #2
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could be that register_globals is set to off which is good and you should use $_POST['name'] instead which is recommended.
    Erh

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    Shelby, NC USA
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for replying- the modified code is below:

    page1

    <form action="page2.php" method="post" name="form">
    <input class="input" id="input" type="text" name="name" size="30" />
    </form>

    page2

    (code in page2 redirects to page3)

    page3

    $name = $_POST['name'];
    echo $name;

    Echo name still returns nothing and register_globals is off.

    This is very strange because normally something like this is dead simple. However, it's been my experience over the years that the 'dead simple' stuff can get you, too.

    If my thinking is correct, 'echo $name;' should work on page2 and 'echo $_POST['name'];' should work on page2 or 3. Any thoughts?
    Earl Parker II

  4. #4
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    page1 

    <form action="page2.php" method="post" name="form"
    <
    input class="input" id="input" type="text" name="name" size="30" /> 
    </
    form

    page2 

    session_start
    (); 
    $_SESSION['name'] = $_POST['name']; 

    page3 

    session_start
    (); 
    echo 
    $_SESSION['name']; 
    Above is what your first post code should look like to work properly. Try that.
    Erh

  5. #5
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    page1

    <form action="page2.php" method="post" name="form">
      <
    input class="input" id="input" type="text" name="name" size="30" />
    </
    form>

    page2

    session_start
    ();
    $_SESSION['name'] = $_POST['name'];

    page3

    session_start
    ();
    echo 
    $_SESSION['name']; 
    Edit:

    Damnit, too late.

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    Shelby, NC USA
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mandibal and Gaheris, you guys are good. It works now. The solution seems obvious in retrospect- then again, most solutions do.

    Through the time and generosity of you two, and others like you, I've been able to learn a great deal on this forum. Once again, thank you very much!
    Earl Parker II


Bookmarks

Posting Permissions

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