【发布时间】:2013-07-10 15:56:18
【问题描述】:
我想知道如何使用此代码验证用户名或电子邮件(不是两者,因为我设法做到了)是否已经在我的数据库中?
<?php
/**
* Register User
*/
if (isset($_POST['register'])) {
$username = $_POST["username"];
$email = $_POST["email"];
$password = $_POST["password"];
$salt = "Not important";
$password_hash = crypt($password, "$2y$". $salt);
if (strlen($username) > 20) {
echo "Username is too big";
}elseif (strlen($password) > 32) {
echo "Password is too big";
}elseif (strlen($email) > 100) {
echo "E-Mail is too big";
}else{
$sth = $dbh->prepare('SELECT username, email FROM user WHERE username = ? AND email = ?');
$sth->execute(array($username, $email));
if ($result = $sth->fetch(PDO::FETCH_OBJ)) {
print $result->username . "Username and email correct";
}else{
echo "Username or email incorrect"; //This is where I want to know how can I check one after another?
}
}
}else{
echo "Not important";
}
?>
谢谢
【问题讨论】:
标签: pdo