...

View Full Version : session_register not working with multiple forms



engimommy
07-08-2007, 07:16 AM
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>

_Aerospace_Eng_
07-08-2007, 07:31 AM
register_globals needs to be on for session_register() to work. You should use $_SESSION['ptype'] instead.

engimommy
07-08-2007, 05:40 PM
register_globals is ON and I tried $_SESSION['ptype'] and it didn't work either.

_Aerospace_Eng_
07-08-2007, 06:10 PM
This


echo $ptype; // DO NOT SEE ptype HERE!!!
Needs to be

echo $_SESSION['ptype'];

CFMaBiSmAd
07-08-2007, 06:40 PM
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.

engimommy
07-08-2007, 09:10 PM
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:

//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:


//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:


//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:


//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:


//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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum