title: Inserting and Joining tables at the same time
body: <p>I am trying to insert some values to the database via a form, but for that to happen tables must be joined, and the way that I have done it is not not working for me.... As it relates to the security issues in the code, that will be dealt with after, but for now I would be extremely grateful for some help...the data is not being stored in the database, after values are entered inside the form and the save button is clicked the form just empties itself</p>
  
  <pre><code>&lt;?php
  session_start();
  include('php/connectdb.php');
  
  if(isset($_POST['firstname']) &amp;&amp; isset($_POST['middlename']) &amp;&amp; isset($_POST['lastname']) &amp;&amp; isset($_POST['address']) &amp;&amp; isset($_POST['home_num']) &amp;&amp; isset($_POST['cell_num']) &amp;&amp; isset($_POST['email']) &amp;&amp; isset($_POST['trn']) &amp;&amp; isset($_POST['hiredate']) &amp;&amp; isset($_POST['status']) &amp;&amp; isset($_POST['location']) &amp;&amp; isset($_POST['shift']) &amp;&amp; isset($_POST['rank']) &amp;&amp; isset($_POST['dob']) &amp;&amp; isset($_POST['maritalstatus']) &amp;&amp; isset($_POST['gender']) &amp;&amp; isset($_POST['height']) &amp;&amp; isset($_POST['weight']) &amp;&amp; isset($_POST['helmet_size']) &amp;&amp; isset($_POST['coat_size']) &amp;&amp; isset( $_POST['pant_size']) &amp;&amp; isset($_POST['boot_size']) &amp;&amp; isset($_POST['glove_size']))
  {
      $firstname = ucfirst($_POST['firstname']);
      $middlename = ucfirst($_POST['middlename']);
      $lastname = ucfirst($_POST['lastname']);
      $address = $_POST['address'];
      $home_num = $_POST['home_num'];
      $cell_num = $_POST['cell_num'];
      $email = $_POST['email'];
      $trn = $_POST['trn'];
      $hiredate = $_POST['hiredate'];
      $status = $_POST['status'];
      $location = $_POST['location'];
      $shift = $_POST['shift'];
      $rank = $_POST['rank'];
      $dob = $_POST['dob'];
      $maritalstatus = $_POST['maritalstatus'];
      $gender = $_POST['gender'];
      $height = $_POST['height'];
      $weight = $_POST['weight'];
      $kinname = ucfirst($_POST['kinname']);
      $kinnumber = $_POST['kinnumber'];
      $helmet_size = $_POST['helmet_size'];
      $coat_size = $_POST['coat_size'];
      $pant_size = $_POST['pant_size'];
      $boot_size = $_POST['boot_size'];
      $glove_size = $_POST['glove_size'];
      $transfer = $_POST['transfer'];
  
      $transferTo = $_POST['transferTo'];
      $dateTransferredTo = $_POST['dateTransferredTo'];
      $transferFrom = $_POST['transferFrom'];
      $dateTransferredFrom = $_POST['dateTransferredFrom'];
      $rankTransferredWith = $_POST['rankTransferredWith'];
  
  
      $username = $_POST['username'];
      $password = $_POST['password'];
  
      if(!empty($firstname) &amp;&amp; !empty($middlename) &amp;&amp; !empty($lastname) &amp;&amp; !empty($address) &amp;&amp; !empty($home_num) &amp;&amp; !empty($cell_num) &amp;&amp; !empty($email) &amp;&amp; !empty($trn) &amp;&amp; !empty($hiredate) &amp;&amp; !empty($status) &amp;&amp; !empty($location) &amp;&amp; !empty($shift) &amp;&amp; !empty($rank) &amp;&amp; !empty($dob) &amp;&amp; !empty($maritalstatus) &amp;&amp; !empty($gender) &amp;&amp; !empty($height) &amp;&amp; !empty($weight) &amp;&amp; !empty($helmet_size) &amp;&amp; !empty($coat_size) &amp;&amp; !empty($boot_size) &amp;&amp; !empty($glove_size) &amp;&amp; !empty($transfer))
      {
          if($transfer == 'Yes'){
              $transfer = 1;
      }
      else{
          $transfer = 0;
      }
  
      $query1 = "INSERT INTO firefighterinfo(`firefighterinfo`.`firstName`, `firefighterinfo`.`middleName`, `firefighterinfo`.`lastName`, `firefighterinfo`.`address`, `firefighterinfo`.`telephone1`, `firefighterinfo`.`telephone2`, `firefighterinfo`.`emailAddress`, `firefighterinfo`.`taxRegistrationNo`, `firefighterinfo`.`hireDate`, `firefighterinfo`.`status`, `stationlocation`.`exactlocation`, `firefighterinfo`.`workShift`, `rank`.`rank`, `firefighterinfo`.`dateOfBirth`, `firefighterinfo`.`maritalStatus`, `firefighterinfo`.`gender`, `firefighterinfo`.`height`, `firefighterinfo`.`weight`, `firefighterinfo`.`kinName`, `firefighterinfo`.`kinContactNo`, `firefighterinfo`.`helmetSize`, `firefighterinfo`.`coatSize`, `firefighterinfo`.`pantSize`, `firefighterinfo`.`bootSize`, `firefighterinfo`.`gloveSize`, `firefighterinfo`.`transfer`)                     VALUES('$firstname', '$middlename', '$lastname', '$address', '$home_num', '$cell_num', '$email', '$trn', '$hiredate', '$status', '$location', '$shift', '$rank', '$dob', '$maritalstatus', '$gender', '$height', '$weight', '$kinname', '$kinnumber', '$helmet_size', '$coat_size', '$pant_size', '$boot_size', '$glove_size', '$transfer')
                  SELECT `firefighterinfo`.fighterID`, `stationlocation`.`exactlocation`, `rank`.`rank` 
                  FROM `firefighterinfo`
                  INNER JOIN `stationlocation` ON `firefighterinfo`.`StationLocation_locationID` = `stationlocation`.locationID
                  INNER JOIN `rank` ON `firefighterinfo`.`Rank_rankID` = `rank`.`rankID`";
  
      $query2 = "INSERT INTO transfer(`transferToStation`,`transferToDate`,`transferFromStation`,`transferFromDate`,`rankTranferredWith`) VALUES('$transferTo', '$dateTransferredTo', '$transferFrom', '$dateTransferredFrom', '$rankTransferredWith')";
  
      $query3 = "INSERT INTO user(`username`, `password`) VALUES ('$username','$password')";
  
      if($_POST['kinname'] == '' || $_POST['kinnumber']== ''){
          $_POST['kinname'] = null;
          $_POST['kinnumber'] = null;
      }
  
      $result = false;
      if(mysql_query('BEGIN')){
          if(mysql_query($query1) &amp;&amp; mysql_query($query2) &amp;&amp; mysql_query($query3))
          {
              $result = mysql_query('COMMIT');
              echo '&lt;script type="text/javascript"&gt;
                  alert("Insert Successful!");
                &lt;/script&gt;';
          }
          else
          {
              mysql_query('ROLLBACK');
              echo '&lt;script type="text/javascript"&gt;
                  alert("Insert Unsuccessful!");
                &lt;/script&gt;';
          }
      }
  }
  
  }
  ?&gt;
  </code></pre>