0
<!--first page [p1.php]-->
            <!DOCTYPE html>
            <html>
                <head>
                </head>
                <body>
                    <form method = 'post' action = 'p2.php'>
                        Form <input type = 'text' name = 'form' /><br><br>
                        <input type = 'submit' value = 'Next' />
                    </form>
                </body>
            </html>
<!--second page [p2.php]-->
            <?php               
            //Log inputs
                $form = $_POST['form'];
            //Echo variables
                echo "
                        <form method = 'post' action= 'p3.php'> 
                            $form<br>
                            <b>Question 1: </b>Type websites's name<br>
                            <b>Website </b><input type = 'text' name = 'website' /><br><br>
                            <input type = 'submit' value = 'Submit' />
                        </form>
                    ";
            ?>
<!--page 3 [p3.php]--> 
            <?php           
            //Log inputs
                $form= $_POST['$form'];
                $website = $_POST['website'];
            //Echo variables
                echo "$form $website<br>";
            ?>
            On [p3.php] it gives me an error stating:

Notice: Undefined index: form in [path to p3.php] on line 3 stackoverflow

How do I make it so that p3.php will display both $form and $website from p2.php?

Pradeep
  • 9,667
  • 13
  • 27
  • 34

3 Answers3

0

Your p3.php should be :

<?php           
   //Log inputs
   $form= $_POST['form'];
   $website = $_POST['website'];
   //Echo variables
   echo "$form $website<br>";
?>

You have given $form in $_POST that should be only form

0

You are doing wrong on page 2 and page 3.

On page 2:

change your code like this.

<?php
//Log inputs
$form = $_POST['form'];
//Echo variables
echo "
    <form method = 'post' action= 'p3.php'> 
        $form<br>
        <input type='hidden' value='$form' name='form'/>
        <b>Question 1: </b>Type websites's name<br>
        <b>Website </b><input type = 'text' name = 'website' /><br><br>
        <input type = 'submit' value = 'Submit' />
    </form>
    ";
?>

Use input type hidden and named it 'form' and put the value from form at p1.php then.

On p3 do like this.

<?php           
    //Log inputs
    $form= $_POST['form'];
    $website = $_POST['website'];
    //Echo variables
    echo "$form $website<br>";
?>

Get the value of input hidden named 'form' from p2.php

Aljay
  • 456
  • 7
  • 21
0

Add the following line before </form> in p2.php

<input type='hidden' name='form' value='$form'>

If you're going to have a more of these you may want to store your variables in a cookie (or as URL parameters if the user does not have cookies enabled).

Mr Glass
  • 1,186
  • 1
  • 6
  • 14