PHP mysql基于另一个表将数据插入表中

I'm tring to insert data into a table based on the user on another table like: personal_information,leave_table where personal_information.person_id=leave_table.person_id and personal_information.person_id=$person_id

The user is applying for leave day but must insert the data into his own record I hope i'm being clear

if ((isset($_POST["MM_insert"])) && ($_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());
}

update:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

$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 > 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());
}

}

Blockquote

try it.

 $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 ='".$_POST['person_id']."'" 
    $result = mysql_query($select_query);
    $no = mysql_num_rows($result);
    if($no > 0)
    {
        insert/update here
    }