我正在做一個登錄/註冊系統,我根本找不到爲什麼輸入的用戶名不會檢查數據庫中是否存在用戶名。檢查用戶是否存在:插入數據庫而不檢查?
電子郵件代碼完美地檢查是否存在現有電子郵件,但即使存在現有電子郵件,用戶名也會通過!
這裏是用戶名密碼:
$query = $db->prepare("SELECT * FROM `users` WHERE `username`=:username");
$query->bindParam(1, $username, PDO::PARAM_STR);
$count = $query->execute(array(":username" => strip_tags(addslashes($_POST['username']))));
if ($query->rowCount() == 1)
{
$errors[] = "Time to be original! That user already exists!";
}
這裏是工作郵件代碼:
$query = $db->prepare("SELECT * FROM `users` WHERE `email`=:email");
$count = $query->execute(array(":email" => strip_tags(addslashes($_POST['email']))));
if ($query->rowCount() == 1)
{
$errors[] = "Please pick a new email! That email is taken!";
}
爲什麼地球上你應聘'用strip_tags(和addslashes())'? – eggyal