这对于基于条件的情况(如果已批准或已拒绝)是必需的。提交具有 25 行 30 个字段的网格类型的表单以进行批量插入。最后插入的 25 行将插入到 temp_Orders 表中,然后根据 if 批准,需要立即将相同的数据(temp_Orders 中的最后插入行)复制到 real_Orders。
$query = "insert into temp_users (fname,sname,lname,email,dob,date_signup,date_expire) values ";
$count = count($_POST['fname']);
for($x=0;$x < $count; $x++)
{
$fname = $_POST['fname'][$x];
$sname = $_POST['sname'][$x];
$lname = $_POST['lname'][$x];
$dob = $_POST['dob'][$x];
$email = $_POST['email'][$x];
echo $fname . $sname . $lname . $dob . $email . '<br>';
$emty_tbl = "TRUNCATE temp_users";
$result_emty_tbl = mysql_query($emty_tbl);
if(!$result_emty_tbl){
die(mysql_error());
@mysql_free_result($result_emty_tbl);
}
$query .= "(
'$fname',
'$sname',
'$lname',
'$email',
'$dob',
'$today',
'$nextyear')";
/* If not last iteration, add a comma and a space */
if ($x < ($count - 1)) {
$query .= ", ";
}
$result = mysql_query($query);
}
if(!$result){
die(mysql_error());
@mysql_free_result($result);
} else {
$totalRID = mysql_affected_rows();
$lastRID = mysql_insert_id();
echo "Total records <b>" . $totalRID . " </b>entered into the database!" . "<br>";
echo "Current record number <b>" . $lastRID . " </b>entered into the database!" . "<br>";
echo "<form name='postbackid' method='post'>
<input type='hidden' name='lastrecord' value='$lastRID'>
<input type='button' value='Approved' name='approved' onclick='return Approved();'>
<input type='button' value='Declined' name='declined' onclick='return Declined();'>
</form>";
}
}
}
$postbackid=$_POST['lastrecord'];
echo $postbackid;
$sqlinsert = "INSERT INTO users (fname, sname, lname, dob, email, date_signup, date_expire)
SELECT fname, sname, lname, dob, email, date_signup, date_expire
FROM temp_users
WHERE id='$postbackid'";
$resultinsert = mysql_query($sqlinsert, $link);