When I test the following code it doesn't update the email address. After I click on the save button it displays the original email address not the new email address. What have I done wrong? Can someone please help me? Thanks in advance.
Code:
// the save button
if (isset($_POST['save'])) {
// get the email address
$email = $_POST['email'];
// get the current password
$currentpassword = $_POST['currentpassword'];
// get the new password
$newpassword = $_POST['newpassword'];
// get the
$newpassword2 = $_POST['newpassword2'];
if ($email == '') {
$arrErrors['email'] = 'You have deleted the email address please refresh the page to display the email address again.';
}
if (strlen($currentpassword) < 6) {
$arrErrors['currentpassword'] = 'Please enter a password that is 6 or more characters in length.';
}
if ((strlen($newpassword) > 6) AND ($newpassword2 == '')){
$arrErrors['newpassword2'] = 'Please enter the password again in the confirm new password field.';
}
if (count($arrErrors) == 0) {
$username = mysql_real_escape_string($_COOKIE['username']);
$email = mysql_real_escape_string($_POST['email']);
$currentpassword = mysql_real_escape_string($_POST['currentpassword']);
$newpassword = mysql_real_escape_string($_POST['newpassword']);
$newpassword2 = mysql_real_escape_string($_POST['newpassword2']);
$update = "UPDATE `users` SET `email` = '$email', `password` = '$newpassword' WHERE `username` = '$username'";
if (mysql_query($update)) {
header ('Location: updated.php');
} else {
print "Could not add the entry because: " . mysql_error() . ". The query was $result.";
}
} else {
// The error array had something in it. There was an error.
// Start adding error text to an error string.
$strError = '<div class="formerror"><p>Please check the following and try again:</p><ul>';
// Get each error and add it to the error string
// as a list item.
foreach ($arrErrors as $error) {
$strError .= "<li>$error</li>";
}
$strError .= '</ul></div>';
}
}