好的,我还有另外一个问题,现在修复了代码:
{
//Check if user already exists
$un_check = mysql_query("SELECT Username FROM users WHERE Username = '$un'");
if(mysql_num_rows($un_check) >0) {
echo "Username already exists";
}
else{
// Username Free
}
但是数据库仍然允许用户名相同。 此外,即使它说“用户名已存在”,我仍然创建帐户?
任何想法?
答案 0 :(得分:2)
似乎拼写错误$un
改为$un_check
,
if(mysql_num_rows($un_check) >0) {...
至少在开发环境中始终打开PHP错误,
error_reporting(E_ALL);
注意: Please, don't use mysql_*
functions in new code。它们不再被维护and are officially deprecated。请参阅red box?转而了解prepared statements,并使用PDO或MySQLi - this article将帮助您确定哪个。如果您选择PDO here is a good tutorial。
答案 1 :(得分:0)
更改: -
if(mysql_num_rows($un) >0)
到
if(mysql_num_rows($un_check) >0)
答案 2 :(得分:0)
试试这个
$un_check = mysql_query("SELECT Username FROM users WHERE Username = 'POSTVALUE'");
if(mysql_num_rows($un_check) >0) {
echo "Username is taken";
}
else{
// Username Free
}