[Solved] Passing values between multiple pages php


Put all of that fields in just one form and validate the action or put validation into php before frontend start, I prefer the first one to your case, it’s easier:

FILTERING IN THE ACTION

<?php
 if (empty($_POST['user_name'])){
       $action = 'page1.php';
       $structure = "<h2>Please enter your user name and age</h2>";
       $submit="Review";
  } else {
       $action = 'page2.php'; 
       $phrase="";
       $user_name = $_POST['user_name'];
       $age = $_POST['age'];
       $structure="<h2>Below are the details entered:</h2><br>
                     <h2>Name: </h2>$user_name
                      <h2>Age: </h2>$age
                       <td bgcolor="#EAEAEA" style="color:#003399"><input type="checkbox" name="occupation[]" value="QA">QA</td>
                       <td bgcolor="#EAEAEA" style="color:#003399"><input type="checkbox" name="occupation[]" value="Tester">Tester</td>";
echo "<br>";
       $submit="Add to DB";
  }

echo "<form action='{$action}' method=\"post\">";
echo "<h2>Your Name.  *</h2><input type="text" name="user_name">";
echo "<br><br>";
echo "<h2>Your Age.  *</h2><input type="text" name="age">";
echo "<br><br>";
echo $structure;
echo "<div><input type="submit" value="{$submit}"></div>";
echo "</form>";

?>

PS: Avoid all those echoes, put just plain html and use php where it needed, it’s better. TD’s outside tables are utterly wrong, remove then, use divs instead and organize them with CSS.

solved Passing values between multiple pages php