title: session form data across multiple pages and insert into mysql?
body: <p>can someone help me please, im trying to submit a form over 3 pages. theres 3 text area fields in each and im using session start to echo the form data other the pages.</p>
  
  <p>so then at the end all i have to do is echo out the form data and insert it into the mysql table ptb_registrations.</p>
  
  <p>for some reason though its not working and im getting the error updating database error. i have been working on this for a few hours im sorry to say and i can not figure it out. please can someone help me and show me where i might be going wrong.</p>
  
  <p>page 1:</p>
  
  <pre><code>&lt;?php
  session_start();
  ?&gt;
  
  &lt;form class="" method="post" action="register_p2.php"&gt;
  &lt;input type="text" id="first_name" name="first_name" placeholder="First Name" /&gt;
  &lt;input type="text" id="last_name" name="last_name" placeholder="Last Name" /&gt;
  &lt;input type="email" id="email" name="email" placeholder="Email"  /&gt;
  &lt;input type="submit" value="Next &gt;"  /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>page 2:</p>
  
  <pre><code>&lt;?php
  session_start();
  // other php code here
  
  $_SESSION['first_name'] = $first_name;
  $_SESSION['last_name'] = $last_name;
  $_SESSION['email'] = $email;
  ?&gt;
  &lt;form name="myForm" method="post" action="register_p3.php" onsubmit="return validateForm()" &gt;
  &lt;input type="text" id="date_of_birth" name="date_of_birth" placeholder="D.O.B 10/02/1990" /&gt;
  &lt;input type="text" id="number" name="number" placeholder="Mobile Number" /&gt;
  &lt;input type="text" id="confirm" name="confirm" placeholder="Are You a UK resident?"  /&gt;
  &lt;input type="submit" value="Next &gt;"  /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>page 3:</p>
  
  <pre><code>&lt;?php
  session_start();
  // other php code here
  
  $_SESSION['first_name'] = $first_name;
  $_SESSION['last_name'] = $last_name;
  $_SESSION['email'] = $email;
  $_SESSION['dat_of_birth'] = $date_of_birth;
  $_SESSION['number'] = $number;
  ?&gt;
  
  &lt;form class="" method="post" action="register_p4.php"&gt;
  &lt;input type="text" id="display_name" name="date_of_birth" placeholder="Display Name" /&gt;
  &lt;input type="password" id="password" name="password" placeholder="Password" /&gt;
  &lt;input type="password" id="password2" name="password2" placeholder="Password (Confirm)"  /&gt;
  &lt;input type="submit" value="Next &gt;"  /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>page 4: (mysql function)</p>
  
  <pre><code>&lt;?php
  session_start();
  // other php code here
  
  $_SESSION['first_name'] = $first_name;
  $_SESSION['last_name'] = $last_name;
  $_SESSION['email'] = $email;
  $_SESSION['dat_of_birth'] = $date_of_birth;
  $_SESSION['number'] = $number;
  $_SESSION['display_name'] = $display_name;
  $_SESSION['password'] = $password;
  ?&gt;
  
  &lt;?php
  ////// SEND TO DATABASE
  
  
  /////////////////////////////////////////////////////////
  
  // Database Constants
  define("DB_SERVER", "localhost");
  define("DB_USER", "root");
  define("DB_PASS", "");
  define("DB_NAME", "database");
  
  // 1. Create a database connection
  $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
  if (!$connection) {
      die("Database connection failed: " . mysql_error());
  }
  
  // 2. Select a database to use
  $db_select = mysql_select_db(DB_NAME,$connection);
  if (!$db_select) {
      die("Database selection failed: " . mysql_error());
  }
  //////////////////////////////////////////////////////////////
  $query="INSERT INTO ptb_registrations (ID,
  first_name,
  last_name,
  email,
  date_of_birth,
  contact_number,
  display_name,
  password
   )
  VALUES('NULL',
  '".$first_name."',
  '".$last_name."',
  '".$email."',
  '".$date_of_birth."',
  '".$number."',
  '".$display_name."',
  '".$password."'
  )";
  mysql_query($query) or die ('Error updating database');
  ?&gt;
  &lt;?php
  function confirm_query($result_set) {
                  if (!$result_set) {
                      die("Database query failed: " . mysql_error());
                  }
          }
  function get_user_id() {
      global $connection;
      global $email;
      $query = "SELECT *
                  FROM ptb_registrations
                  WHERE email = \"$email\"
                  ";
          $user_id_set = mysql_query($query, $connection);
          confirm_query($user_id_set);
          return $user_id_set;
          }
  ?&gt;
  &lt;?php
  $user_id_set = get_user_id();
  while ($user_id = mysql_fetch_array($user_id_set)) {
      $cookie1 = "{$user_id["id"]}";
      setcookie("ptb_registrations", $cookie1, time()+3600);  /* expire in 1 hour */
  
  }
  ?&gt;
  
  &lt;?php include ('includes/send_email/reg_email.php'); ?&gt;
  
  &lt;? ob_flush(); ?&gt;
  </code></pre>