chien pin wang
chien pin wang

Reputation: 567

php post data in if else statement

I have a sign up form came with 3 pages. I use jquery $post to post error message back without refresh 2nd php page will check all data. if all data correct than it will send to 3rd page(agreement page). If user click agree in 3rd page, than all data will write into database.

However I have problem to post data to 3rd page in php by using if & else

This is a sign up form. Therefor I can't use $_GET[]

ex. else{header("location:agreement.php?email=somedata&pw=somedata");}

is any way I can pass those data to 3rd page in php?

1st page

    <form>
    <input type="text" name="email"/>
    (some input)...

    <input type="button" onclick="get();"/>
    </form>



JQUERY
function get(){
    $('#error').hide();
    $.post('signup.php',{firstname:signup.firstname.value,...},
    function(output){$('#error').html(output).fadeIn(50);})
    }

2nd page

signup.php
    if(will check everything){echo "error";}
      //Jquery will output error without refresh the page
    else{
        [Need to POST all sign up data from 1st page to 3rd page]
        header("to agreement.php");
    }

3rd page

agreement.php
if user tick agree. All sign up data will insert into database.

Upvotes: 1

Views: 647

Answers (4)

Amir
Amir

Reputation: 4111

Example for sending email to 3rd php

function get(){
var email = $('#email').val();
    $('#error').hide();
    $.post('signup.php',{firstname:signup.firstname.value,email:email,...},
    function(output){$('#error').html(output).fadeIn(50);})
    }

signup.php
$email = $_GET['email'];
    if(will check everything){echo "error";}
      //Jquery will output error without refresh the page
    else{
        [Need to POST all sign up data from 1st page to 3rd page]
        header("to agreement.php?".$email);

agreement.php
$email = $_POST['email'];
if user tick agree. All sign up data will insert into database.
    }

Upvotes: 0

Robert
Robert

Reputation: 20286

Store it in session or if you show pages store it in you can also use CURL but it's "hard" way to make it. With curl you can send POST with all variables you want to another page.

Upvotes: 1

Munir Vora
Munir Vora

Reputation: 51

When You Add Data Then On First Form Add Data into Table and use record_id in session and on all other Form Pages Just Update That database Record

Upvotes: 1

KillerX
KillerX

Reputation: 1466

Why do you not store the data in the session? Then you can easily retrive it on page 3 without having it to pass to the client, then the server and back to the client again.

Upvotes: 1

Related Questions