如何检查数据库中是否已使用用户名? 我已经尝试过这段代码,但它无法正常工作
$usernamecheck=mysql_query("SELECT userName FROM websiteusers WHERE userName='$_POST['username']'");
答案 0 :(得分:1)
你可以试试这个:
$user = $_POST['username'];
$usernamecheck=mysql_query("SELECT `userName` FROM `websiteusers`
WHERE userName='$user'", $dbcon);
if(mysql_num_rows($usernamecheck)>=1){
echo $user." is already taken";
}else{
echo $user."is available";
}
答案 1 :(得分:0)
$usernamecheck=mysql_query("SELECT userName FROM websiteusers WHERE userName='".$_POST['username']."'");