我想把数据插入到基于另一个表上的用户的表中,如:
personal_information,leave_table where personal_information.person_id=leave_table.person_id and personal_information.person_id=$person_id
用户正在申请休假日,但必须将数据插入自己的记录中 我希望我很清楚
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());
}
更新
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
答案 0 :(得分:0)
$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
}