How to pass multiple variables across multiple pages?

前端 未结 7 595
长发绾君心
长发绾君心 2020-11-30 13:37

My website involves a user submitting data over several pages of forms. I can pass data submitted on one page straight to the next page, but how do I go about sending it to

相关标签:
7条回答
  • 2020-11-30 13:49

    Use SESSION variable or hidden input field

    0 讨论(0)
  • 2020-11-30 14:01

    if you don't want cookies or sessions: use a hidden input field in second page and initialize the variable by posting it like:

    page2----
    
    $name=$_POST['name'];  /// from page one
    
    <form method="post" action="page3.php">
     <input type="text" name="req">
     <input type="hidden" name="holdname" value="<? echo "$name"?>"> 
     ////////you can start by making the field visible and see if it holds the value
    </form>
    
    page3----
    
    $name=$_POST['holdname'];    ////post the form in page 2
    $req=$_POST['req'];    ///// and the other field
    echo "$name, Your name was successfully passed through 3 pages";
    
    0 讨论(0)
  • 2020-11-30 14:06

    You can create sessions, and use posts. You could also use $_GET to get variables from the URL.

    Remember, if you aren't using prepared statements, make sure you escape all user input...

    0 讨论(0)
  • 2020-11-30 14:10

    You could store the data in a cookie on the user's client, which is abstracted into the concept of a session. See PHP session management.

    0 讨论(0)
  • 2020-11-30 14:10

    As mentioned by others, saving the data in SESSION is probably your best bet.

    Alternatly you could add the data to a hidden field, to post it along:

    page2:

     <input type="hidden" name="username" value="<?php echo $name;?>"/>
    

    page3

    echo "hello $_POST['username'};
    
    0 讨论(0)
  • 2020-11-30 14:11

    Use sessions:

    session_start(); on every page

    $_SESSION['name'] = $_POST['name'];
    

    then on page3 you can echo $_SESSION['name']

    0 讨论(0)
提交回复
热议问题