我正在尝试建立一个登录/注册系统,当你按下登录时,它应该说存在......
<?php
include 'core/init.php';
function user_exists($username){
$username = sanitize($uusername);
$query = mysql_query("SELECT COUNT (`user_id`) FROM `users` WHERE `username` = '$username'");
$result = mysql_query($query) or die(mysql_error()); // Check if query was successful
$row = mysql_fetch_array($result); // fetch the first row
return ($row[0] > 1); // If there is one or more users with this name, return true.
}
这是应该使页面显示“存在”的代码:
<?php
include 'core/init.php';
if(user_exists('Zuzima') === true) {
echo 'exists';
}
die();
if (empty($_POST) === false) {
$username = $_POST['username'];
$password = $_POST['password'];
if(empty($username) === true || empty($password) === true){
$errors[] = 'You need to a username and password.';
} else if (user_exists($username) === false) {
$errors[] = 'We can\'t find that username. Have you registered?';
}
}
?>
请帮助我,我至少已经为此工作了 6 个月。