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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    session_register not working with multiple forms

    Forgive me - I am new at this. I have a muti-form site where I need a variable from one form to be visible across many forms. For instance, in form 3 I get variable ptype and need to see it in form 4. In each of my forms my "action" is to call myphpcode.php - which performs tasks based on the inputs of the form just used. I am trying to use session_register - but it just doesn't seem to make ptype visible throughout all my forms... Below is an example of what I did. I apologize for the overload of code - I am just at my wits end. Thanks for any help !!!

    //form1.php
    <?php
    session_start();
    ?>

    <html>

    <title>blabla </title>
    </head>

    <body bgcolor="#9999ff" link="#999933" vlink="#999933"alink="#999933">

    <font face="Arial" color="#000000">
    <form name="form1" action="http://myphpcode.php" style="width: 750px;">

    //FORM STUFF ….
    <br>
    <br>

    <input type="submit" name ="submitbutton" value="Next" />
    </form>

    </font>
    </body>
    </html>

    //form2.php
    <?php
    session_start();
    ?>
    <html>

    <title>blabla </title>
    </head>
    <body bgcolor="#9999ff" link="#999933" vlink="#999933" alink="#999933">

    <font face="Arial" color="#000000">
    <form name="form2" action="http://myphpcode.php" method="get" style="width: 750px;">

    //FORM STUFF ..

    <right>&nbsp;</right><right><input type="submit" name ="submitbutton" value="NextOne" /></right>

    </form>
    </font>
    </body>
    </html>

    //form3.php
    <?php
    session_start();
    ?>
    <html>

    <title>blabla</title>
    </head>

    <body bgcolor="#9999ff" link="#999933" vlink="#999933"
    alink="#999933">

    <font face="Arial" color="#000000">


    <form name="form3" action="http://myphpcode.php" style="width: 750px;">


    Which type? <br><br>

    <INPUT TYPE="radio" NAME="ptype" VALUE="A"> A <br>
    <INPUT TYPE="radio" NAME="ptype" VALUE="B"> B<br>
    <INPUT TYPE="radio" NAME="ptype" VALUE="C"> C <br>
    <INPUT TYPE="radio" NAME="ptype" VALUE="D"> D<br>
    <INPUT TYPE="radio" NAME="ptype" VALUE="E"> E<br>
    <br>

    <right>&nbsp;</right><right><input type="submit" name ="submitbutton" value="NextTwo" /></right>

    <?php

    session_register("ptype"); // Store variables
    session_write_close (); // Store variables

    ?>
    </form>
    </font>

    <form METHOD="LINK" ACTION="http://www. form2.php">
    <p>
    <input type="submit" value="Back" ></p>
    </form>
    </body>
    </html>

    //form 4
    <?php
    session_start();
    ?>
    <html>

    <title>blabla </title>
    </head>

    <body bgcolor="#9999ff" link="#999933" vlink="#999933"
    alink="#999933">

    <font face="Arial" color="#000000">


    <form name="form4" action="http://myphpcode.php" style="width: 1250px;">

    // FORM STUFF ..

    <right>&nbsp;<input type="submit" name ="submitbutton" value="NextThree" /></right>

    </form>

    <form METHOD="LINK" ACTION="http://www. form3.php">
    <p>
    <input type="submit" value="Back" ></p>
    </form>

    </font>
    </body>
    </html>

    //myphpcode.php
    <html>

    <title>blabla</title>


    <body bgcolor="#9999ff" link="#999933" vlink="#999933"
    alink="#999933">

    <font face="Arial" color="#000000">


    <?php

    ob_start();


    $submitbutton = $_GET['submitbutton'] ;




    switch($submitbutton) {
    //form1
    case "Next":
    … code

    break;

    //form2
    case "NextOne":
    … code
    break;

    //form3
    case "NextTwo":

    echo $ptype; // SEE ptype HERE!!!

    break;

    //form 4
    case "NextThree":


    echo $ptype; // DO NOT SEE ptype HERE!!!



    break;

    }

    ?>
    </font>
    </body>
    </html>

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    register_globals needs to be on for session_register() to work. You should use $_SESSION['ptype'] instead.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    register_globals is ON and I tried $_SESSION['ptype'] and it didn't work either.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    This
    PHP Code:
    echo $ptype// DO NOT SEE ptype HERE!!! 
    Needs to be
    PHP Code:
    echo $_SESSION['ptype']; 
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,131
    Thanks
    2
    Thanked 328 Times in 320 Posts
    If you edit your first post and wrap the code for each file in separate php code tags so that we can see which code belongs to each file, you will have a better chance of someone seeing what you are trying to accomplish.

    The session_register() and related functions have been depreciated since 22-Apr-2002 and should not be used. You should also not be writing any new code that relies on register_globals being on.

    By having a form field name the same as a variable and having register_globals on, causes them to refer to the same storage and the last source in the variables_order "EGPCS" wins and will overwrite the other. Either turn register globals off (as php.net recommends) or use unique variable names for everything.

    The only valid method="..." for forms are "post" and "get". Your method="link" is invalid and only does not work because browsers ignore a lot of invalid tags and parameters.
    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.

  • #6
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay - I made all my methods equal to "post", got rid of session_register and replaced it with $_SESSION and I still am having problems seeing ptype in form 4 ... I broke out each section for better viewing ... any ideas ?? Thanks for all the help so far!!


    FORM 1:
    PHP Code:
    //form1.php
    <?php
    session_start
    ();
    ?>

    <html>

    <title>blabla </title>
    </head>

    <body bgcolor="#9999ff" link="#999933" vlink="#999933"alink="#999933">

    <font face="Arial" color="#000000">
    <form name="form1" method = "post" action="http://myphpcode.php" style="width: 750px;">

    //FORM STUFF ….
    <br>
    <br>

    <input type="submit" name ="submitbutton" value="Next" />
    </form>

    </font> 
    </body>
    </html>
    FORM 2:
    PHP Code:
    //form2.php
    <?php 
    session_start
    ();
    ?>
    <html>

    <title>blabla </title>
    </head>
    <body bgcolor="#9999ff" link="#999933" vlink="#999933" alink="#999933">

    <font face="Arial" color="#000000">
    <form name="form2" action="http://myphpcode.php" method = "post" style="width: 750px;">

    //FORM STUFF ..

    <right>&nbsp;</right><right><input type="submit" name ="submitbutton" value="NextOne" /></right>

    </form>
    </font> 
    </body>
    </html>
    FORM 3:
    PHP Code:
    //form3.php
    <?php 
    session_start
    ();
    ?>
    <html>

    <title>blabla</title>
    </head>

    <body bgcolor="#9999ff" link="#999933" vlink="#999933"
    alink="#999933">

    <font face="Arial" color="#000000">


    <form name="form3" method = "post" action="http://myphpcode.php" style="width: 750px;">


    Which type? <br><br>

    <INPUT TYPE="radio" NAME="ptype" VALUE="A"> A <br> 
    <INPUT TYPE="radio" NAME="ptype" VALUE="B"> B<br>
    <INPUT TYPE="radio" NAME="ptype" VALUE="C"> C <br> 
    <INPUT TYPE="radio" NAME="ptype" VALUE="D"> D<br>
    <INPUT TYPE="radio" NAME="ptype" VALUE="E"> E<br>
    <br>

    <right>&nbsp;</right><right><input type="submit" name ="submitbutton" value="NextTwo" /></right>

    </form>
    </font> 

    <form METHOD="post" ACTION="http://www. form2.php">
    <p>
    <input type="submit" value="Back" ></p>
    </form>
    </body>
    </html>
    FORM 4:
    PHP Code:
    //form 4
    <?php 
    session_start
    ();
    ?>
    <html>

    <title>blabla </title>
    </head>

    <body bgcolor="#9999ff" link="#999933" vlink="#999933"
    alink="#999933">

    <font face="Arial" color="#000000">


    <form name="form4" method = "post" action="http://myphpcode.php" style="width: 1250px;">

    // FORM STUFF ..

    <right>&nbsp;<input type="submit" name ="submitbutton" value="NextThree" /></right>

    </form>

    <form METHOD="post" ACTION="http://www. form3.php">
    <p>
    <input type="submit" value="Back" ></p>
    </form>

    </font> 
    </body>
    </html>

    MYPHPCODE.php:
    PHP Code:
    //myphpcode.php
    <html>

    <title>blabla</title>


    <body bgcolor="#9999ff" link="#999933" vlink="#999933"
    alink="#999933">

    <font face="Arial" color="#000000">


    <?php

    ob_start
    ();


    $submitbutton $_POST['submitbutton'] ;




    switch(
    $submitbutton) {
    //form1
    case "Next":
    … code

    break;

    //form2
    case "NextOne":
    … code
    break;

    //form3
    case "NextTwo":

      
    $profiletype $_POST['ptype']; 
      
    $_SESSION['protype']= $profiletype;

       echo 
    $ptype// I SEE IT!!!
       
    echo $profiletype// I SEE IT!!!
       
    echo $_SESSION['protype']; // I SEE IT!!!

      
    break;

    //form 4
    case "NextThree":

       echo 
    $_SESSION['protype']; // DO NOT SEE 
       
    echo $profiletype// DO NOT SEE 
       
    echo $ptype// DO NOT SEE ptype HERE!!!



    break;

    }

    ?>
    </font> 
    </body>
    </html>


  •  

    Posting Permissions

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