Session Variable Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hobbes2006
    New Member
    • Feb 2008
    • 2

    #1

    Session Variable Help

    I am trying to move data from one page to another using $_SESSION, without putting the information on a database.

    This is what I have. My issue is when I have $_SESSION['first_name']='john' it passes the $_SESSION to the next page but when I have the $_POST in it will not pass the information that is put in the input. Why is it doing this? Also my register_global s is turned to off.

    Thanks in advance.
    Code:
    <?php
    session_start();
    $_SESSION['first_name'] = $_POST['first_nameID'];
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <form name="form1" method="POST" action="testconfirm.php">
    0.<br/>
    <input type="text" name="first_name" id="first_nameID"/><br/><br/>
    
    <input type="submit" name="submit"/>
    </form>
    </body>
    </html>
  • Bodyloss
    New Member
    • Feb 2008
    • 6

    #2
    Hey there
    The "name" part of a form input is the Name thats passed when you submit the form, so try changing that to "first_name ID".
    Also, just to make sure its getting there, try changing your first line of code to:
    Code:
    if (isset($_POST['first_nameID']) {
      //this checks to make sure that the POST variable is set
      if (ctype_alnum($_POST['first_nameID'])) {
        //this makes sure that first_nameID is only made of charectesr 
        //and numbers
        $_SESSION['first_nameID'] = $_POST['first_nameID'];
      } else {
        $_SESSION['first_nameID'] = false;
      }
    } else {
      $_SESSION['first_nameID'] = false;
    }
    This will just make sure that people dont submit malicious data though your form.
    Hope that sorts it out.

    Comment

    • hobbes2006
      New Member
      • Feb 2008
      • 2

      #3
      Well I tried it and it still did not work. The form is not passing it to the variable. What would cause this?

      Comment

      Working...