1

I've finally got the first page of my registration page working. The user has to select one of three options before continuing to the next page. The problem I am having now is that the first page is not sending the data to the next page. Here is the code for

Registration_1.php:

$reg_type = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (!empty($_POST["Reg_type"])) {
        //$reg_type=$_POST["Reg_type"];
        //header('Location: Registration_2.php?rtype='.$reg_type);
        $reg_type=$_POST["Reg_type"];
        header('Location: Registration_2.php');
    }
}
?>

<form name="frmtype" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" >
<input type="radio" name="Reg_type" value="1"/> Registering myself with credit card or bank account <br/>
<input type="radio" name="Reg_type" value="2"/> Registering multiple people using credit card or bank account <br/>
<input type="radio" name="Reg_type" value="3"/> Registering multiple people using a purchase order <br/>
<input type="submit" name="Submit" value="Submit" />
<?php
if(isset($_POST["Submit"]) && !isset($_POST["Reg_type"]))
    echo "Please select an option";
?>
</form>

Registration_2.php

<?php
$regtype=$_POST["Reg_type"];

echo "regtype value is:" . $regtype;
if($regtype==1) {
?>

However regtype is blank, meaning i'm not getting any data from the previous page. Can anyone tell me what the problem is?

FirmView
  • 3,130
  • 8
  • 34
  • 50
Richard
  • 5,840
  • 36
  • 123
  • 208
  • For what it's worth, you need to be very careful using `$_SERVER` as your form's action. Also, this question has nothing to do with Dreamweaver. – David Sep 09 '12 at 04:43
  • 3
    There is no POST when using redirects (`header('Location: ....')`). Either use GET-Variables (`http_build_query`) or sessions to forward the variable. – vstm Sep 09 '12 at 04:46
  • It has to do with sessions. Store the value in a session variable, then you can get that value on any page – FirmView Sep 09 '12 at 04:47

4 Answers4

2
session_start();
$reg_type=$_POST["Reg_type"];
$_SESSION['cust_type'] = $reg_type;

and in any page,

session_start();
echo $_SESSION['cust_type']; 

for more informations,

http://matthom.com/archive/2005/02/19/php-passing-variables-across-pages

http://www.plus2net.com/php_tutorial/variables.php

PHP Pass variable to next page

http://mrarrowhead.com/index.php?page=php_passing_variables.php

http://php.net/manual/en/reserved.variables.session.php

Community
  • 1
  • 1
FirmView
  • 3,130
  • 8
  • 34
  • 50
1

This is because you are doing a redirect, so the post data no longer exists.

You have a few options. Instead of doing a redirect, you could do an include.

You could store the data (session, database, etc)

You could append the data to the redirect

header('Location: Registration_2.php?Reg_type=' . $_POST['Reg_type');

then use $_GET on the Registration_2 instead of post.

Kris
  • 6,094
  • 2
  • 31
  • 46
0

You're posting your form to page1 and then redirecting to page2. Page2 doesn't have access to the posted data due to the redirect (the post is not carried along).

What you should do is process the data in page1 and store it before redirecting (eg, in a session, or use a query string like you've commented out).

Another note, when you call for a redirect using header, make sure you also exit or die immediately afterwards like the php documentation mentions (since you cannot guarantee the page will stop processing there).

temporalslide
  • 957
  • 6
  • 9
0

First of all, when you use header to redirect, the POST variables are lost. You need to pass the variables with GET in order to retrieve them on Registration_2.php.

Registration_1.php

//...
header('Location: Registration_2.php?Reg_type=' . $_POST["Reg_type"]);
//...

and Registration_2.php:

$regtype=$_GET["Reg_type"];

echo "regtype value is:" . $regtype; if($regtype==1) {
Spontifixus
  • 6,570
  • 9
  • 45
  • 63
christopher
  • 615
  • 5
  • 11