数据库不检查用户名是否免费

时间:2013-06-25 13:11:35

标签: php html mysql xampp

好的,我还有另外一个问题,现在修复了代码:

{ 
   //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
}

但是数据库仍然允许用户名相同。 此外,即使它说“用户名已存在”,我仍然创建帐户?

任何想法?

3 个答案:

答案 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,并使用PDOMySQLi - 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
}