Insert and Update Server Behaviors in the Same Form
I have a php form that is inserting into one table and then updating another table. I have the form inserting the record first and then I want it to update the other table. I am starting to learn and understand php, but I don't know how to have the update function perform after it inserts the records. I suppose it is something along the lines if you insert this record, then update this record and then go to the redirect page. I do know that it is going to the redirect page after it inserts the record, but I don't know how to tell it not to go to the $insertGoTo. I want it to run the next update function and then go to the $insertGoTo and not the $updateGoTo. Thanks in advance for any help.
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO employee (CompId, empfirstname, empmiddleint, emplastname, EmpType, EmpStatus) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['CompId'], "int"),
GetSQLValueString($_POST['empfirstname'], "text"),
GetSQLValueString($_POST['empmiddleint'], "text"),
GetSQLValueString($_POST['emplastname'], "text"),
GetSQLValueString($_POST['EmpType'], "text"),
GetSQLValueString($_POST['EmpStatus'], "text"));mysql_select_db($database_dotweb, $dotweb);
$Result1 = mysql_query($insertSQL, $dotweb) or die(mysql_error());$insertGoTo = "Roster.php?CompId=" . $_POST['CompId'] . "";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE company SET CompanyType=%s WHERE CompId=%s",
GetSQLValueString($_POST['CompanyType'], "text"),
GetSQLValueString($_POST['CompId'], "int"));mysql_select_db($database_dotweb, $dotweb);
$Result1 = mysql_query($updateSQL, $dotweb) or die(mysql_error());$updateGoTo = "purchases.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
