I can't seem to get this right for the life of me and it is most likely something simple I am overlooking so I am hoping someone here can point me in the right direction. I currently have a membership script setup. It has email templates that it sends for forgotten passwords, when an account is registered, etc. I want the system to send an email when a user updates their account details. Here is the code I currently have:
function editAccount($uname, $upass)
{
global $db, $msgOk, $msgAlert, $showMsg;
$upass = sanitize($upass);
$uname = sanitize($uname);
$userrow = User::getUserInfo($uname);
if ($_POST['email'] == "")
$this->msgs['email'] = "The field Email Address cannot be left blank. Please enter a value.";
if ($_POST['name'] == "")
$this->msgs['name'] = "The field First and Last Name cannot be left blank. Please enter a value.";
if ($_POST['address'] == "")
$this->msgs['address'] = "The field Address cannot be left blank. Please enter a value.";
if ($_POST['city'] == "")
$this->msgs['city'] = "The field City cannot be left blank. Please enter a value.";
if ($_POST['state'] == "")
$this->msgs['state'] = "The field State cannot be left blank. Please enter a value.";
if ($_POST['zip'] == "")
$this->msgs['zip'] = "The field ZIP Code cannot be left blank. Please enter a value.";
if ($_POST['dob'] == "")
$this->msgs['dob'] = "The field Date of Birth cannot be left blank. Please enter a value.";
if ($_POST['previousaddress'] == "")
$this->msgs['previousaddress'] = "The field Previous Address cannot be left blank. Please enter a value.";
if ($_POST['previouscity'] == "")
$this->msgs['previouscity'] = "The field Previous City cannot be left blank. Please enter a value.";
if ($_POST['previousstate'] == "")
$this->msgs['previousstate'] = "The field Previous State cannot be left blank. Please enter a value.";
if ($_POST['previouszip'] == "")
$this->msgs['previouszip'] = "The field Previous Zip Code cannot be left blank. Please enter a value.";
if (User::emailExists($_POST['email']) and $_POST['email'] != $userrow['email'])
$this->msgs['email'] = "Entered Email Address is already in use.";
if (!User::isValidEmail($_POST['email']))
$this->msgs['email'] = "Entered Email Address is not valid.";
if (empty($this->msgs)) {
$email = sanitize($_POST['email']);
$name = sanitize($_POST['name']);
if ($upass != "") {
$upass = md5($upass);
} else
$upass = $userrow['password'];
$data = array(
'email' => $email,
'name' => $name,
'password' => $upass,
'notify' => intval($_POST['notify'])
);
$db->update("users", $data, "id = '" . $userrow['id'] . "'");
if ($db->affected()) {
if (intval($_POST['send_notify']) == 1) {
require_once("class_mailer.php");
$mail_template = $setup->getEmailTemplateById(3);
$body = str_replace(
array('[NAME]', '[USERNAME]', '[PASSWORD]', '[URL]', '[SITE_NAME]'),
array($data['name'], $data['username'], $_POST['password'], $setup->set['site_url'], $setup->set['site_name']), $mail_template['body']
);
$mail = $mailer->sendMail($data['email'], $mail_template['subject'], $body);
}
redirect_to("index.php?do=profile&updated");
} else
$msgAlert = "<span>Alert!</span> Nothing to update";
} else {
$showMsg = "<div class=\"msgError\"><span>Your user profile could not be saved due to the following error(s):</span><ul class=\"error\">";
foreach ($this->msgs as $msg) {
$showMsg .= "<li>" . $msg . "</li>\n";
}
$showMsg .= '</ul></div>';
}
return true;
}
I added the code after if ($db->affected()) { and it simply updates the profile and loads a blank page. Do I just have a comma or bracket in the wrong place or something? Please help if you can Thanks!