我有更新帳戶信息的表單。在一種形式下,我有姓名,用戶名,電子郵件,公司,密碼。比方說,我想要做的就是改變我的名字,我仍然使用這種形式,所有其他領域保持不變。在更新表單中,我有一個電子郵件和用戶名檢查程序,確保它們尚未被使用。所以現在,即使我不更改我的電子郵件地址或用戶名,它也會被提交給檢查代碼。如何防止第二次重複檢查?
如何解決它,這樣它不會阻止它,如果它屬於同一個人:
// checks if the email is in use
if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$emailcheck = $_POST['email'];
$check = mysql_query("SELECT email FROM accounts WHERE email = '$emailcheck'")
or die(mysql_error());
$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0) {
print("here i basically show the form once again highlighting the error)");
die('');
}
在旁註;你希望在列上使用'UNIQUE'索引嗎? – Wrikken 2011-03-30 20:02:18