Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- form1.php
- ----------------------------------------------------
- <form method="post" action="form2.php">
- <p>Name:
- <input type="text" name="name">
- </p>
- <p>Email address
- <input type="text" name="emailaddress">
- <input type="submit" value="Go To Step 2">
- </p>
- </form>
- +=================================================+
- form2.php
- ----------------------------------------------------
- <?php
- //start the session
- session_start();
- //Get and store posted values in the session variables
- foreach ($_POST as $key => $value){
- $_SESSION[$key] = $value;
- } ?>
- <form method="post" action="form3.php">
- <p>Male
- <input type="radio" name="gender" value="Male">
- Female
- <input type="radio" name="gender" value="Female">
- </p>
- <p>Age:
- <input type="text" name="age">
- </p>
- <p>Location:
- <input type="text" name="location">
- <input type="submit" value="Go To Step 3">
- </p>
- </form>
- +=================================================+
- form3.php
- ----------------------------------------------------
- <?php
- //start the session
- session_start();
- //Get and store posted values in the session variables
- foreach ($_POST as $key => $value){
- $_SESSION[$key] = $value;
- } ?>
- <form method="post" action="pageprocess.php">
- <p>Employment status:
- <input type="text" name="employmentstatus">
- </p>
- <p>Hobbies:
- <input type="text" name="hobbies">
- <input type="submit" value="Finish">
- </p>
- </form>
- +=================================================+
- pageprocess.php
- ----------------------------------------------------
- <?php
- session_start();
- // Get Variables
- $userid = $_SESSION['userid']; // Session
- $name = $_SESSION['name']; // Session
- $emailaddress = $_SESSION['emailaddress']; // Session
- $gender = $_SESSION['gender']; // Session
- $age = $_SESSION['age']; // Session
- $location = $_SESSION['location'] ; // Session
- $employment_status = $_POST['employmentstatus']; // Post
- $hobbies = $_POST['hobbies']; // Post
- // Set Connection
- $con=mysqli_connect("localhost","username","password","databasename");
- // Check connection
- if (mysqli_connect_errno()){echo "Failed to connect to MySQL: " . mysqli_connect_error();}
- // Create SQL
- $sql="INSERT INTO userinfo (
- userid,
- name,
- emailaddress,
- gender,
- age,
- location,
- employmentstatus,
- hobbies
- )
- VALUES
- ( '" . $userid . "',
- '" . $name . "',
- '" . $emailaddress . "',
- '" . $gender . "',
- '" . $age . "',
- '" . $location . "',
- '" . $employment_status . "',
- '" . $hobbies . "'
- )";
- if (!mysqli_query($con,$sql)) {
- die('Error: ' . mysqli_error($con));
- }
- echo "1 record added";
- mysqli_close($con); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement