-1

我有以下代码,因此在将记录写入数据库之前,它会检查是否存在已存在的用户名.....

$duplicate=mysql_query("SELECT username FROM user WHERE username='" . $username . "'"); 


if ($duplicate <> $username) {
        $insertquery = mysql_query("insert into user                (username, password, lastlogin, address1, address2,             address3, email) values ('$userid', '$password', now            (),'$address1','$address2','$address3','$email')");
    //$msg = "Successfully Registered!";
    $msg = mysql_fetch_assoc($username);
  } else {

    $pass_err = "This Username Is Already In Use!";
    $msg = "This Username Is Already In Use!";
    $userid="";
    $err_flag="False";
    $dupe="";
    $numrecords=0;
}
}

我错过了什么?它总是说它已经存在,当我知道它不存在时......

4

2 回答 2

3

缺少获取语句

$duplicate=mysql_query("SELECT username FROM user WHERE username='" . $username . "'"); 
$row=mysql_fetch_array($duplicate);

if ($row['username'] == $username) {
    // your code
}
于 2013-09-27T19:06:30.597 回答
1

mysql查询后,需要取结果

$duplicate = mysql_result($duplicate);
于 2013-09-27T19:06:23.020 回答