`
mysql_connect("host","admin","password");//database connection
mysql_select_db("dbname");
$order="INSERT INTO members (username, password) VALUES ('$_POST[username]','$_POST[password]')";
$doopquery = mysql_query("SELECT username FROM members WHERE username='$_POST[username]' ")
if ($doopquery) {
echo("Username Taken");
} else {
$result = mysql_query($order);
echo("Account Registered");
}
>`
我到目前为止我的数据库连接很好,当我到达$ doop
时答案 0 :(得分:0)
$username=mysql_real_escape_string($_POST['username']);
$doopquery = mysql_query("SELECT username FROM members WHERE username='$username' ");
if(mysql_num_rows($doopquery)==0){
//username not found
}
else{
//username already exists
}
缺少'用户名
失踪;在$ doopquery结束时
答案 1 :(得分:0)
这样做:
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$query = "SELECT username FROM members WHERE username='{$username}'";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0) {
echo "Username Already Taken!";
}else{
$query = "INSERT INTO members (username, password) VALUES ('{$username}','{$password}')";
if(mysql_query($query)) {
echo "Account Registered!";
}else{
echo "Account Register Failed!";
}
}