title: insert into 3 different table using pdo and mysql
body: <p>I am using php mysql , I am trying to insert into 3 different tables but the third table do not receive values  and this is the last table .The Idea is  I want to get the user_id inserted in all tables at the point of creating a new account  of the user so that when I want to update other fields I will just refer to that user_id which is a foreign key in those other tables . 
  Bellow is my code :</p>
  
  <pre><code>&lt;?php
      #connect to the db
      require_once('db.inc.php');
  ?&gt;
  
  &lt;?php 
      $date_created = date('y-m-d h:i:s a');
      $username = (isset($_POST['username'])) ? trim($_POST['username']): '';
      $Previllage =(isset($_POST['Previllage']))? trim($_POST['Previllage']): '';
  
      #second tanble values 
      $title=(isset($_POST['title']))? trim($_POST['title']): '';
      $firstname=(isset($_POST['firstname']))? trim($_POST['firstname']): '';
      $lastname=(isset($_POST['lastname']))? trim($_POST['lastname']): '';
      $client_code=(isset($_POST['client_code']))? trim($_POST['client_code']): '';
      $job_approval=(isset($_POST['job_approval']))? trim($_POST['job_approval']): '';
      $address=(isset($_POST['address']))? trim($_POST['address']): '';
      $cell=(isset($_POST['cell']))? trim($_POST['cell']): '';
      $tel=(isset($_POST['tel']))? trim($_POST['tel']): '';
      $email=(isset($_POST['email']))? trim($_POST['email']): '';
      $company=(isset($_POST['company']))? trim($_POST['company']): '';
      $province=(isset($_POST['province']))? trim($_POST['province']): '';
      $ip_address=$SERVER['REMOTE_ADDR'];
  
      if(empty($_POST['firstname'])){
          exit();
      }
  
      #check box 
      if(isset($_POST['department_type'])) {
          $value = implode(",", $_POST['department_type']);   
      } else {
          $value = "";
      }
      #check box 
  
      #Image code 
      $target ='../t/images/';
      $target = $target.basename($_FILES['imagename']['name']);
      $pic = ($_FILES['imagename']['name']);
      ########################################################
      #end
  
      try {
          $query="INSERT INTO tish_user(username,Previllage,date_created)
                  VALUES(:username,:Previllage,:date_created)";
          $insert = $con-&gt;prepare($query);
          $insert-&gt;execute(array(
                      ':username'=&gt;$username,
                      ':Previllage'=&gt;$Previllage,
                      ':date_created'=&gt;$date_created)
                  );
  
          # insert into another table
          $query="INSERT INTO tish_clientinfor(
                  user_id,title,firstname,lastname,
                  client_code,department_type,job_approval,province,
                  company,address,cell,tel,email,date_registered)
                  VALUES(
                  LAST_INSERT_ID(),
                  :title,:firstname,:lastname,
                  :client_code,:department_type,:job_approval,:province,:company,:address,
                  :cell,:tel,:email,
                  :date_registered)";
  
          $insert = $con-&gt;prepare($query);
          $insert-&gt;execute(array(
                      ':title'=&gt;$title,
                      ':firstname'=&gt;$firstname,
                      ':lastname'=&gt;$lastname,
                      ':client_code'=&gt;$client_code,
                      ':department_type'=&gt;$value,
                      ':job_approval'=&gt;$job_approval,
                      ':province'=&gt;$province,
                      ':company'=&gt;$company,
                      ':address'=&gt;$address,
                      ':cell'=&gt;$cell,
                      ':tel'=&gt;$tel,
                      ':email'=&gt;$email,
                      ':date_registered'=&gt;$date_created)
                  );
  
          #intert into the security table 
          $query = "INSERT INTO tish_security(ip_address,user_id,date_registered)
                  VALUES(
                  :ip_address,
                  LAST_INSERT_ID(),
                  :date_registered)";
          $insert = $con-&gt;prepare($query);
          $insert-&gt;execute(array(
                      ':ip_address'=&gt;$ip_address,
                      ':date_registered'=&gt;$date_created)
                  );
  
          # insert into another table
      } catch(PDOException $e) {
          echo $e-&gt;getMessage();
      }
  ?&gt;
  </code></pre>