I have a pretty simple User Details form, and I need to be able to display an outcome page for each of these scenarios…
- Your User Details were updated
- Your User Details have not changed
- Your User Details could not be updated due to a System Error
Here is he code I have…
// ************************
// Update Member Record. *
// ************************
// Build query.
$q1 = "UPDATE member
SET first_name=?,
gender=?,
birth_year=?,
location=?,
occupation=?,
interests=?,
about_me=?,
updated_on=NOW()
WHERE id=?
LIMIT 1";
// Prepare statement.
$stmt1 = mysqli_prepare($dbc, $q1);
// Bind variables to query.
mysqli_stmt_bind_param($stmt1, 'ssissssi', $firstName, $gender, $birthYear, $location,
$occupation, $interests, $aboutMe, $sessMemberID);
// Execute query.
mysqli_stmt_execute($stmt1);
// Verify Update.
if (mysqli_stmt_affected_rows($stmt1)==1){
// Update Succeeded.
$detailsChanged = TRUE;
// Update Session Variable.
$_SESSION['sessFirstName'] = $firstName;
}else{
// Update Failed.
$_SESSION['resultsCode'] = 'DETAILS_NEW_DETAILS_FAILED_2132';
// Set Error Source.
$_SESSION['errorPage'] = $_SERVER['SCRIPT_NAME'];
// Redirect to Display Outcome.
header("Location: " . BASE_URL . "/account/results.php");
// End script.
exit();
}//End of UPDATE MEMBER RECORD
// Display Form Outcome
if (empty($_SESSION['resultsCode'])){
if ($detailsChanged == TRUE){
// Changes Succeeded.
$_SESSION['resultsCode'] = 'DETAILS_NEW_DETAILS_SET_2131';
}elseif ($detailChanged == FALSE){
// No Changes.
$_SESSION['resultsCode'] = 'DETAILS_NO_CHANGES_2272';
}
// Set Error Source.
$_SESSION['errorPage'] = $_SERVER['SCRIPT_NAME'];
// Redirect to Outcome Page.
header("Location: " . BASE_URL . "/account/results.php");
// End script.
exit();
}//End of DISPLAY FORM OUTCOME
The above code is not working, because if I load the Form, change nothing, and click “Submit”, it always follows the $detailsChanged=TRUE path…
What do I need to do to fix this issue??
Thanks,
Debbie