Advertisement
dpDesignz

Multiple page PHP form elements for user3267724

Feb 3rd, 2014
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.62 KB | None | 0 0
  1. form1.php
  2. ----------------------------------------------------
  3. <form method="post" action="form2.php">
  4.     <p>Name:
  5.     <input type="text" name="name">
  6.     </p>
  7.     <p>Email address
  8.   <input type="text" name="emailaddress">
  9.       <input type="submit" value="Go To Step 2">
  10.     </p>
  11. </form>
  12. +=================================================+
  13. form2.php
  14. ----------------------------------------------------
  15. <?php
  16. //start the session
  17. session_start();
  18. //Get and store posted values in the session variables
  19. foreach ($_POST as $key => $value){
  20.     $_SESSION[$key] = $value;
  21. } ?>
  22. <form method="post" action="form3.php">
  23.   <p>Male
  24.   <input type="radio" name="gender" value="Male">
  25.     Female
  26.   <input type="radio" name="gender" value="Female">
  27.   </p>
  28.   <p>Age:
  29.     <input type="text" name="age">
  30.   </p>
  31.   <p>Location:
  32.     <input type="text" name="location">
  33.     <input type="submit" value="Go To Step 3">
  34.   </p>
  35. </form>
  36. +=================================================+
  37. form3.php
  38. ----------------------------------------------------
  39. <?php
  40. //start the session
  41. session_start();
  42. //Get and store posted values in the session variables
  43. foreach ($_POST as $key => $value){
  44.     $_SESSION[$key] = $value;
  45. } ?>
  46. <form method="post" action="pageprocess.php">
  47.   <p>Employment status:
  48.   <input type="text" name="employmentstatus">
  49.   </p>
  50.   <p>Hobbies:
  51.     <input type="text" name="hobbies">
  52.     <input type="submit" value="Finish">
  53.   </p>
  54. </form>
  55. +=================================================+
  56. pageprocess.php
  57. ----------------------------------------------------
  58. <?php
  59. session_start();
  60. // Get Variables
  61. $userid = $_SESSION['userid']; // Session
  62. $name = $_SESSION['name']; // Session
  63. $emailaddress = $_SESSION['emailaddress']; // Session
  64. $gender = $_SESSION['gender']; // Session
  65. $age = $_SESSION['age']; // Session
  66. $location = $_SESSION['location'] ; // Session
  67. $employment_status = $_POST['employmentstatus']; // Post
  68. $hobbies = $_POST['hobbies']; // Post
  69. // Set Connection
  70. $con=mysqli_connect("localhost","username","password","databasename");
  71. // Check connection
  72. if (mysqli_connect_errno()){echo "Failed to connect to MySQL: " . mysqli_connect_error();}
  73. // Create SQL
  74. $sql="INSERT INTO userinfo (
  75.         userid,
  76.         name,
  77.         emailaddress,
  78.         gender,
  79.         age,
  80.         location,
  81.         employmentstatus,
  82.         hobbies
  83. )
  84. VALUES
  85. (       '" . $userid . "',
  86.         '" . $name . "',
  87.         '" . $emailaddress . "',
  88.         '" . $gender . "',
  89.         '" . $age . "',
  90.         '" . $location . "',
  91.         '" . $employment_status . "',
  92.         '" . $hobbies . "'
  93. )";
  94. if (!mysqli_query($con,$sql)) {
  95.     die('Error: ' . mysqli_error($con));
  96. }
  97. echo "1 record added";
  98. mysqli_close($con); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement