redirecting to page with newly inserted row as a parameter
I have an admin form for storing member registrations.
Sometimes, there may be several people from the same organisation to add to the system so rather than re-key all of the data, I want to add a ‘duplicate’ button to a member update page, which will copy the fields from the existing form into the members table, then redirect to the new record so it can be edited.
In the Insert Record Server Behavior, I set the session name to be MemberID and then set the redirect URL to "../member_update.php?MemberID=".$_SESSION['MemberID'];
At first, I couldn’t get the session value to appear as the url parameter, so I added @session_start(); to line 1 of my page.
Now, I get a parameter, but the value is incorrect, the ID is 1 less than the value of the newly entered row
<?php
// WA DataAssist Insert
if (isset($_POST["duplicate"]) || isset($_POST["duplicate_x"])) // Trigger
{
$WA_connection = $PowerCMSConnection;
$WA_table = "tblmembers";
$WA_sessionName = "MemberID";
$WA_redirectURL = "../member_update.php?MemberID=".$_SESSION['MemberID'];
if (function_exists("rel2abs")) $WA_redirectURL = $WA_redirectURL?rel2abs($WA_redirectURL,dirname(__FILE__)):"";
$WA_keepQueryString = false;
$WA_fieldNamesStr = "MemberGroupID|MemberUserName|MemberPassword|MemberFirstName|MemberLastName|userLevel|Display|Active";
$WA_fieldValuesStr = "".((isset($_POST["MemberGroup"]))?$_POST["MemberGroup"]:"") ."" . $WA_AB_Split . "".((isset($_POST["MemberUserName"]))?$_POST["MemberUserName"].'(Copy)':"") ."" . $WA_AB_Split . "".((isset($_POST["StandardMemberPassword"]))?md5($_POST["StandardMemberPassword"]):"") ."" . $WA_AB_Split . "".((isset($_POST["MemberFirstName"]))?$_POST["MemberFirstName"]:"") ."" . $WA_AB_Split . "".((isset($_POST["MemberLastName"]))?$_POST["MemberLastName"]:"") ."" . $WA_AB_Split . "".((isset($_POST["UserLevel"]))?$_POST["UserLevel"]:"") ."" . $WA_AB_Split . "".((isset($_POST["chkdisplay"]))?$_POST["chkdisplay"]:"") ."" . $WA_AB_Split . "".((isset($_POST["chkactive"]))?$_POST["chkactive"]:"") ."";
$WA_columnTypesStr = "none,none,NULL|',none,''|',none,''|',none,''|',none,''|none,none,NULL|none,none,NULL|none,none,NULL";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode($WA_AB_Split, $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_PowerCMSConnection;
mysql_select_db($WA_connectionDB, $WA_connection);
@session_start();
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id($WA_connection);
if ($WA_redirectURL != "") {
$WA_redirectURL = str_replace("[Insert_ID]",$_SESSION[$WA_sessionName],$WA_redirectURL);
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>