我有一个包含用户详细信息的表单和一个更新语句,如果用户愿意,它将更新这些详细信息,我添加了验证,以便电子邮件不能与另一个帐户相关联,因此 if($checkuser != 0)
该声明的问题在于,如果用户不更改他们的电子邮件并更新他们的详细信息,他们将收到一个错误消息,指出电子邮件已经存在。
我想在电子邮件存在检查之后进行集成,else if(($_POST["myusername"]) == ($row['email']))
然后继续更新。(myusername 变量名称包含电子邮件)这意味着如果发布的电子邮件与他们当前的电子邮件相同,则继续更新。
但是我迷路了,因为我对 PHP 比较陌生,所以我在括号和括号方面遇到了麻烦。
这是我的代码
if($_POST['usubmit']=='Update')
{
$Uerr = array();
if (!$_POST['fullname'] || !$_POST['myusername'])
{
$Uerr[] = '» Name or Email must be filled in!';
}
if (!checkEmail($_POST['myusername']))
{
$Uerr[]='» Your email is not valid!';
}
// If there are no errors
if(!count($Uerr))
{
/* Now we will check if username is already in use or not */
$queryuser=mysql_query("SELECT * FROM customer WHERE email='" . mysql_real_escape_string($_POST["myusername"]) . "'");
$checkuser=mysql_num_rows($queryuser);
if($checkuser != 0)
{
$Uerr[]='» Sorry this email is already registered!';
}
else
{
$updateDetails = mysql_query("UPDATE customer SET
name = '" . mysql_real_escape_string($_POST["fullname"]) . "',
dob = '" . mysql_real_escape_string($_POST["dob"]) . "',
address = '" . mysql_real_escape_string($_POST["address"]) . "',
email = '" . mysql_real_escape_string($_POST["myusername"]) . "',
telephone = '" . mysql_real_escape_string($_POST["telephone"]) . "'
WHERE cus_id = '$cus_id'");
if ($updateDetails)
$_SESSION['Umsg']['Ureg-success']="» Your details have been updated successfully!";
else {
$Uerr[]='» error updating your account'.mysql_error();
}
}
}
if(count($Uerr))
{
$_SESSION['Umsg']['Ureg-err'] = implode('<br />',$Uerr);
}
header("Location: account.php");
exit;
}