title: Inserting data into database during session
body: <p>I am building a three part signup system using sessions. The first part is on the homepage, there is a login here called form1 and a signup called form2. This question is about signup form2. In form2 the user inserts email and password into the DB table, and the iduser is created auto automatically. A sessions is created, this part works fine. In signup_part2.php using sessions I echo out the iduser and email to prove that the info was inserted into the database. Then in signup_part2.php there is a second form, however when I hit submit nothing is inserted into the database table into those user's fields. <strong>How can I insert data into the DB table during a user's session?</strong></p>
  
  <p>home.php</p>
  
  <pre><code>&lt;?php
  session_start();
  require('connect.php');
  require('header.php');
  $form1 = &lt;&lt;&lt;EOT
  &lt;div id="homebox1"&gt;
      &lt;div id="logohome"&gt;
          &lt;h2&gt;Welcome&lt;/h2&gt;&lt;/br&gt;
  
  
      &lt;/div&gt;
      &lt;div id="homecolumn1"&gt;
          &lt;p&gt;Login&lt;/p&gt;&lt;/br&gt;
          &lt;form id="login" action="home.php" method="POST"&gt;
              &lt;input name="emaillogin" placeholder="email" type="email" rows="20"&gt; &lt;/input&gt;&lt;/br&gt;
              &lt;input name="passwordlogin" placeholder="password" type="password" rows="20"&gt; &lt;/input&gt;&lt;/br&gt;
              &lt;input type="submit" name="submita" value="Log In"&gt; &lt;/input&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  
  EOT;
  $form2 = &lt;&lt;&lt;EOT
  
      &lt;div id="homecolumn2"&gt;
          &lt;p&gt;Sign Up&lt;/p&gt;&lt;/br&gt;
          &lt;form id="signuppart1" action="home.php" method="post"&gt;
              &lt;input name="signupemail" placeholder="email" type="email" rows="20" required&gt; &lt;/input&gt;&lt;/br&gt;
              &lt;input pattern="(?=^.{8,50}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$"  name="signuppassword" placeholder="password" type="password" rows="20" required&gt; &lt;/input&gt;&lt;/br&gt;
              &lt;input name="submitb" type="submit" value="Sign Up"&gt; &lt;/input&gt;
  &lt;/form&gt;
      &lt;/div&gt;
  
  EOT;
  $footer = &lt;&lt;&lt;EOT
      &lt;div id="footerhome1"&gt;
  
  
      &lt;/div&gt;  
  &lt;/div&gt;
  
  EOT;
  
  
  /*-------------------------------------form1----------------------------------------*/
  if(isset($_POST['submita'])){
      $email = mysql_escape_string($_POST['emaillogin']);
      $pass = mysql_escape_string($_POST['passwordlogin']);
  
      $salt = '458mn$8n@bty67mg%563!&amp;78fj^543*41s';
      $pass = md5($pass . $salt); 
  
  
  
  
  $sql = mysql_query ("SELECT * FROM `profile` WHERE `email` = '$email' AND `password`= '$pass' ");
  if(mysql_num_rows($sql) &gt; 0){
      // ADDITIONAL CODE //pull userdata from db
      while($row = mysql_fetch_array($sql)){
         $_SESSION['logged_in']['fnlname'] = $row['fnlname'];       
         $_SESSION['logged_in']['username'] = $row['username'];
         $_SESSION['logged_in']['gender'] = $row['gender'];
      }
      // END ADDITIONAL CODE
  
  
  
      header('location: profile.php');    
  
  }else{
  echo &lt;&lt;&lt;EOT
  &lt;div id="homebox1"&gt;
      &lt;div id="logohome"&gt;
          &lt;h2&gt;Welcome&lt;/h2&gt;&lt;/br&gt;
  
  
      &lt;/div&gt;
      &lt;div id="homecolumn1"&gt;
          &lt;p&gt;Login&lt;/p&gt;&lt;/br&gt;
          &lt;form id="login" action="home.php" method="POST"&gt;
              &lt;input name="emaillogin" placeholder="email" type="email" rows="20"&gt; &lt;/input&gt;&lt;/br&gt;
              &lt;input name="passwordlogin" placeholder="password" type="password" rows="20"&gt; &lt;/input&gt;&lt;/br&gt;
              &lt;input type="submit" name="submita" value="Log In"&gt; &lt;/input&gt;
                  &lt;p style="color:red;"&gt;"Wrong password or username"&lt;/p&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  
  EOT;
  
  }
  }else{
  
  echo $form1;
  }
  /*-------------------------------------form2----------------------------------------*/
  if(isset($_POST['submitb'])){
      //perform verification
      $email1 = $_POST['signupemail'];
      $pass1 = $_POST['signuppassword'];
              if ($pass1 == NULL){
  
                      echo &lt;&lt;&lt;EOT
      &lt;p style="color:red;"&gt;"Enter a password"&lt;/p&gt;
  
  
  EOT;
              exit();
          }
  
  
      $email1 = mysql_escape_string($email1);
      $password = mysql_escape_string($pass1);
  $salt = 'justasalt';
          $password = md5($password . $salt);
  $sql2 = mysql_query("SELECT * FROM `profile` WHERE `email` = '$email1' ");
          if(mysql_num_rows($sql2) &gt; 0){
              echo $form2;
                      echo &lt;&lt;&lt;EOT
  
                  &lt;p style="color:red;"&gt;"Sorry, that email already exists!"&lt;/p&gt;   
  
  
  
  
  
  EOT;
  
              exit();
          }
  else{
  
  
  
  
  
  
  
          mysql_query("INSERT INTO `profile` (`iduser`, `password`, `email`)VALUES(NULL, '$password', '$email1')");
          $sql = mysql_query ("SELECT * FROM `profile` WHERE `email` = '$email1' AND `password`= '$password' ");
  if(mysql_num_rows($sql) &gt; 0){
      // ADDITIONAL CODE //pull userdata from db
      while($row = mysql_fetch_array($sql)){
         $_SESSION['logged_in']['iduser'] = $row['iduser'];       
         $_SESSION['logged_in']['fnlname'] = $row['fnlname'];       
         $_SESSION['logged_in']['username'] = $row['username'];
         $_SESSION['logged_in']['gender'] = $row['gender'];
         $_SESSION['logged_in']['location'] = $row['location'];       
         $_SESSION['logged_in']['website'] = $row['website'];
         $_SESSION['logged_in']['age'] = $row['age'];    
         $_SESSION['logged_in']['joined'] = $row['joined'];          
         $_SESSION['logged_in']['email'] = $row['email'];    
      }
          header("location: signup_part2.php");
  
          }
  }
  }
  else{
  
  echo $form2;
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>signup_part2.php</p>
  
  <pre><code>&lt;?php
  session_start();
  include "connect.php";
  include "header.php";
  $iduser=$_SESSION['logged_in']['iduser'];
  $sql = mysql_query("SELECT * FROM `profile` WHERE `iduser` = '$iduser' ");      
                      while($row = mysql_fetch_array($sql)){
                      $iduser = $row['iduser'];
                      $password = $row['password'];   
                      $email = $row['email'];                     
                      $fnlname = $row['fnlname'];     
                      $username = $row['username'];
                      $joineddate = $row['joineddate'];                       
                      $gender = $row['gender'];   
                      $age = $row['age'];
                      $location = $row['location'];
                      $website = $row['website'];                         
  
  
  
  
  
  }                       
  echo "$iduser $password $email";                            
  $form1 = &lt;&lt;&lt;EOT
  &lt;div id="homebox1"&gt;
      &lt;div id="logohome"&gt;
          &lt;h2&gt;Welcome&lt;/h2&gt;&lt;/br&gt;
  
  
      &lt;/div&gt;
      &lt;div id="signupcolumn1"&gt;
          &lt;p&gt;Please fillout your info&lt;/p&gt;
          &lt;form id="signup2" action="signup_part2.php" method="POST"&gt;
              &lt;p&gt;&lt;input name="fnlname" placeholder="First and Last Name" type="text" size="50" required&gt;*&lt;/br&gt;
              &lt;input name="username" placeholder="Username" type="text" size="50" required&gt;*&lt;/br&gt;         
              &lt;input name="age" placeholder="Your Age" type="" size="50" required&gt;*&lt;/br&gt;&lt;/p&gt;
  &lt;p&gt;&lt;input style="text-align:left;" type="radio" name="gender" value="male"/&gt;Male&lt;/br&gt;
  &lt;input style="text-align:left;" type="radio" name="gender" value="female"/&gt;Female&lt;/br&gt;
  &lt;input style="text-align:left;" type="radio" name="gender" value="blank"/&gt;Leave Blank&lt;/br&gt;&lt;/p&gt;
  
  
              &lt;p&gt;&lt;input name="location" placeholder="Location" type="" size="50" &gt;Opt.&lt;/br&gt;
              &lt;input name="website" placeholder="Website" type="" size="50"&gt;Opt. &lt;/br&gt;&lt;/p&gt;
              &lt;input name="joineddate" placeholder="joineddate" type="hidden" size="50"&gt;
              &lt;input type="submit" name="submita" value="Next"&gt; 
      &lt;/div&gt;
          &lt;/form&gt;
  
  
  EOT;
  if(isset($_POST['submita'])){
      //perform verification
      $fnlname = $_POST['fnlname'];
      $username = $_POST['username'];
      $age = $_POST['age'];
      $gender = $_POST['gender'];
      $location = $_POST['location'];
      $website = $_POST['website'];
      $joineddate = $_POST['joineddate'];
  $iduser=$_SESSION['logged_in']['iduser'];
          /*$fnlname = mysql_escape_string($fnlname);
          $username = mysql_escape_string($username);
          $age = mysql_escape_string($age);
          $gender = mysql_escape_string($gender);
          $location = mysql_escape_string($location);
          $website = mysql_escape_string($website);   */
  $sql1 = mysql_query("SELECT * FROM `profile` WHERE `username` = '$username' ");
          if(mysql_num_rows($sql1) &gt; 0){
              echo "Sorry, that username already exists!";
  
              }else{  
  
  
  
          mysql_query("UPDATE profile SET fnlname='$fnlname' joineddate='$joineddate' gender='$gender' age='$age' location='$location' website='$website' WHERE iduser=$iduser ");
  
  
              }
  
  
  
  }else{
  echo $form1;
  }
  ?&gt;
  </code></pre>