gpt4 book ai didi

php - 为什么我从这段代码中收到 "Query was empty"错误?

转载 作者:行者123 更新时间:2023-11-29 08:30:47 25 4
gpt4 key购买 nike

我正在尝试创建一个登录/注册系统,当您按登录时,它应该说存在...

<?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.




}

下面是使页面显示“Exists”的代码:

<?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 个月。

最佳答案

If there is one or more users with this name, return true.

所以不应该 return ($row[0] > 1); 只是 return ($row[0] >= 1);

关于php - 为什么我从这段代码中收到 "Query was empty"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16682077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com