PDO收集用户名或电子邮件

时间:2013-07-10 15:56:19

标签: pdo

我想知道如何使用此代码验证用户名或电子邮件(不是因为我设法做的)已经在我的数据库中?

<?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";
}


?>

谢谢

1 个答案:

答案 0 :(得分:0)

  

我想知道如果用户名电子邮件

,我该如何验证?      

SELECT用户名,电子邮件FROM user WHERE username =? AND 电子邮件=?'

需要进一步解释吗?