我有以下代码,以便在将记录写入数据库之前,它会检查是否存在已存在的用户名.....
$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;
}
}
我错过了什么?它总是说它已经存在,当我知道它不存在时......
答案 0 :(得分:3)
缺少提取语句
$duplicate=mysql_query("SELECT username FROM user WHERE username='" . $username . "'");
$row=mysql_fetch_array($duplicate);
if ($row['username'] == $username) {
// your code
}
答案 1 :(得分:1)
在mysql查询之后,您需要获取结果
$duplicate = mysql_result($duplicate);