我是 PDO 的新手,正在尝试注册和登录。
当我尝试调试它时,它返回 bool(false) 。无法找出为什么会这样。
<?php
include_once('db.php');
$username = $_POST['username'];
$email = $_POST['email'];
$password = sha1($_POST['password']);
$confirm_password = sha1($_POST['confirm_password']);
$ip = $_SERVER['REMOTE_ADDR'];
$fetchUsers = $db->query("SELECT * FROM `users` WHERE `username` = '$username'");
if(!empty($username) &&
!empty($email) &&
!empty($password) &&
!empty($confirm_password) &&
filter_var($email, FILTER_VALIDATE_EMAIL) &&
$password == $confirm_password &&
$fetchUsers->fetchAll() != $username) {
$insertSQL = "INSERT INTO `users`
(`username`, `email`, `password`, `ip`) VALUES
(:username => '$username', :email => '$email', :password => '$password', :ip => '$ip')";
$insertUser = $db->query($insertSQL);
var_dump($insertUser);
echo '<br /><br />You have successfully registered.';
}
else {
echo '<br /><br />There was an error with your registration.';
}
?>