Results 1 to 3 of 3

Thread: Using $_SESSION properly

  1. #1
    Join Date
    Apr 2013

    Using $_SESSION properly

    I'm having problems with the $_SESSION code.
    I can't retrieve the info on the next page.

    After looking at the manual (which I think lacks enough examples / explanation) I came to this:

    if (empty($_SESSION['count'])) {
    $_SESSION['count'] = 1;
    } else {

    <form enctype="multipart/form-data" method="POST" action="ads.php?<?php echo $_SESSION["count"]; ?>" />
    <input type="hidden" name="PHPSESSID" value="<?php echo $_SESSION["count"]; ?>" />
    Name:<input type="text" name ="name" /><br />
    Book:<input type="text" name ="book" /><br />
    Subject:<input type="text" name ="subject" /><br />
    Price (CAN):<input type="text" name ="price" /><br />
    Description: <br /><textarea cols="40" rows="5" name="description">
    </textarea><br />
    Click to upload:<input type="file" name="pix" /><br />
    <input type="submit" name="Upload" value="Upload Picture" />
    I managed to get the ID to send in a link to the other page.

    But on the next page, when I write:
    echo "<b>Name: </b>" . $_SESSION['name'] . "<br />";

    How do I retrieve the info from the URL using $_SESSION? Also how do I generate the proper text from $_SESSION using the ID from the link.

    I'm open to anything you have in mind.

  2. #2
    Join Date
    Apr 2013
    You do not retrieve data from url with $_SESSION. In your code you have form which has a method "POST". This means that, once your form will be submitted via method you specified(POST in your case), you will be able to get post data via $_POST variables and not via $_SESSION variables.

  3. #3
    Join Date
    Aug 2004
    Yep, session data and form data are two separate things. All you need (normally) to do to access session data is to stick a session_start() in any page where you want to access it (before any output and before any reference to $_SESSION), while your form data will be in $_POST or $_GET as applicable (or you can use $_REQUEST in rare cases where it could be either POST or GET).
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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