I am having trouble with the coding to return the user to the previous page after submitting a form. I understand that it is usually better to create a direct link to the previous page, however there are four entrances to this page and I would like the user to return to their previous page upon submitting. I have listed the code below and I think my problem lies in line 112 or there about. Thank you so much.
<?php session_start(); ?>
<?php require_once('../Connections/Connect.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "1,2";
$MM_donotCheckaccess = "false";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && false) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "AnitasAnimalArk/AnimalArk.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO postshift (UserID, ShiftDay, ShiftDate, ShiftMonth, ShiftYear, ShiftStartHour, ShiftStartMin, ShiftStartTime, ShiftEndHour, ShiftEndMin, ShiftEndTime, ChildcareCentre, Address, City, Telephone, EmployeeFirstName, EmployeeLastName, `Position`, EmailEmployee, EmailCentre, Comments) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['UserID'], "int"),
GetSQLValueString($_POST['ShiftDay'], "text"),
GetSQLValueString($_POST['ShiftDate'], "text"),
GetSQLValueString($_POST['ShiftMonth'], "text"),
GetSQLValueString($_POST['ShiftYear'], "int"),
GetSQLValueString($_POST['ShiftStartHour'], "int"),
GetSQLValueString($_POST['ShiftStartMin'], "int"),
GetSQLValueString($_POST['ShiftStartTime'], "text"),
GetSQLValueString($_POST['ShiftEndHour'], "int"),
GetSQLValueString($_POST['ShiftEndMin'], "int"),
GetSQLValueString($_POST['ShiftEndTime'], "text"),
GetSQLValueString($_POST['ChildcareName'], "text"),
GetSQLValueString($_POST['ChildcareAddress'], "text"),
GetSQLValueString($_POST['ChildcareCity'], "text"),
GetSQLValueString($_POST['ChildcareTelephone'], "int"),
GetSQLValueString($_POST['EmployeeFirstName'], "text"),
GetSQLValueString($_POST['EmployeeLastName'], "text"),
GetSQLValueString($_POST['Position2'], "text"),
GetSQLValueString($_POST['EmployeeUserEmail'], "text"),
GetSQLValueString($_POST['ChildcareEmail'], "text"),
GetSQLValueString($_POST['Comments'], "text"));
mysql_select_db($database_Connect, $Connect);
$Result1 = mysql_query($insertSQL, $Connect) or die(mysql_error());
$insertGoTo = "HTTP_REFERER";
if (isset($_SERVER["HTTP_REFERER"])) {
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_Connect, $Connect);
$query_PostShift = "SELECT * FROM postshift";
$PostShift = mysql_query($query_PostShift, $Connect) or die(mysql_error());
$row_PostShift = mysql_fetch_assoc($PostShift);
$totalRows_PostShift = mysql_num_rows($PostShift);
$query_PostShift = "SELECT * FROM postshift";
$PostShift = mysql_query($query_PostShift, $Connect) or die(mysql_error());
$row_PostShift = mysql_fetch_assoc($PostShift);
$totalRows_PostShift = mysql_num_rows($PostShift);
$query_PostShift = "SELECT * FROM postshift";
$PostShift = mysql_query($query_PostShift, $Connect) or die(mysql_error());
$row_PostShift = mysql_fetch_assoc($PostShift);
$totalRows_PostShift = mysql_num_rows($PostShift);
$query_PostShift = "SELECT * FROM postshift";
$PostShift = mysql_query($query_PostShift, $Connect) or die(mysql_error());
$row_PostShift = mysql_fetch_assoc($PostShift);
$totalRows_PostShift = mysql_num_rows($PostShift);
$colname_Users = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_Users = $_SESSION['MM_Username'];
}
mysql_select_db($database_Connect, $Connect);
$query_Users = sprintf("SELECT * FROM users WHERE UserName = %s", GetSQLValueString($colname_Users, "text"));
$Users = mysql_query($query_Users, $Connect) or die(mysql_error());
$row_Users = mysql_fetch_assoc($Users);
$totalRows_Users = mysql_num_rows($Users);
$colname_Childcare = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_Childcare = $_SESSION['MM_Username'];
}
mysql_select_db($database_Connect, $Connect);
$query_Childcare = sprintf("SELECT * FROM users INNER JOIN childcareinfo ON users.ChildcareID = childcareinfo.ChildcareID WHERE users.UserName = %s", GetSQLValueString($colname_Childcare, "text"));
$Childcare = mysql_query($query_Childcare, $Connect) or die(mysql_error());
$row_Childcare = mysql_fetch_assoc($Childcare);
$totalRows_Childcare = mysql_num_rows($Childcare);
?>