title: PHP mysql Inserting data to a table based on another table
body: <p>I'm tring to insert data into a table based on the user on another table like: 
  <code>personal_information,leave_table where personal_information.person_id=leave_table.person_id and personal_information.person_id=$person_id</code> </p>
  
  <p>The user is applying for leave day but must insert the data into his own record 
  I hope i'm being clear</p>
  
  <pre><code>if ((isset($_POST["MM_insert"])) &amp;&amp; ($_POST["MM_insert"] == "form1")) {
      $insertSQL = sprintf("INSERT INTO leave_table (reqLeave, cause) VALUES (%s, %s)",
          GetSQLValueString($_POST['reqLeave'], "text"),
          GetSQLValueString($_POST['cause'], "text"));
      mysql_select_db($database_leaveReqForm, $leaveReqForm);
      $Result1 = mysql_query($insertSQL, $leaveReqForm) or die(mysql_error());
  }
  </code></pre>
  
  <p>update:</p>
  
  <p>if ((isset($_POST["MM_insert"])) &amp;&amp; ($_POST["MM_insert"] == "form1")) {</p>
  
  <pre><code>$select_query = select pi.person_id from personal_information as pi INNER JOIN leave_table as lt ON pi.person_id=lt.person_id where pi.person_id = $person_id
  $result = mysql_query($select_query);
  $no = mysql_num_rows($result);
  if($no &gt; 0)
  {
  $insertSQL = sprintf("INSERT INTO leave_table (reqLeave, cause) VALUES (%s, %s)",
      GetSQLValueString($_POST['reqLeave'], "text"),
      GetSQLValueString($_POST['cause'], "text"));
  mysql_select_db($database_leaveReqForm, $leaveReqForm);
  $Result1 = mysql_query($insertSQL, $leaveReqForm) or die(mysql_error());
  }
  </code></pre>
  
  <p>}</p>
  
  <blockquote>
    <p><code>Blockquote</code></p>
  </blockquote>