2011-03-30 31 views
0

我有更新帐户信息的表单。在一种形式下,我有姓名,用户名,电子邮件,公司,密码。比方说,我想要做的就是改变我的名字,我仍然使用这种形式,所有其他领域保持不变。在更新表单中,我有一个电子邮件和用户名检查程序,确保它们尚未被使用。所以现在,即使我不更改我的电子邮件地址或用户名,它也会被提交给检查代码。如何防止第二次重复检查?

如何解决它,这样它不会阻止它,如果它属于同一个人:

// 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(''); 
    } 
+0

在旁注;你希望在列上使用'UNIQUE'索引吗? – Wrikken 2011-03-30 20:02:18

回答

1

我不知道乌尔DB是如何被格式化,但用户名添加到SQL应该这样做

// 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' 
         AND NOT(user='$username')") 
    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(''); 
    } 

因此它的外观在电子邮件不是特定用户的:-)

+0

$用户名在第二个变量检查​​?对? – AAA 2011-03-30 20:03:52

+0

谢谢兄弟明白了。 – AAA 2011-03-30 20:09:32

+0

任何时候都不可能有@AAA^_ ^ – Neal 2011-03-30 20:09:55

1

存储是提交表单的原始值的行中,并加载窗体时检查为new value == old value。如果不相等,请检查,否则跳过。

<? 
    if ($_POST['oldemail'] != $_POST['newemail']) { 
     //Do check here 
    } 
    //so on and so on 
?>