У меня есть несколько проблем с моим логином PHP и SQL
Это ошибка, которая показывает;
Warning: mysql_real_escape_string(): Access denied for user ''@'web83.local.one.com' (using password: NO) in /customers/2/2/3/srbportal.com/httpd.www/core/functions/general.php on line 3 Warning: mysql_real_escape_string(): A link to the server could not be established in /customers/2/2/3/srbportal.com/httpd.www/core/functions/general.php on line 3 Warning: mysql_query(): Access denied for user ''@'web83.local.one.com' (using password: NO) in /customers/2/2/3/srbportal.com/httpd.www/core/functions/users.php on line 4 Warning: mysql_query(): A link to the server could not be established in /customers/2/2/3/srbportal.com/httpd.www/core/functions/users.php on line 4 Warning: mysql_result() expects parameter 1 to be resource, boolean given in /customers/2/2/3/srbportal.com/httpd.www/core/functions/users.php on line 4
General.php:
<?php
function sanitize($data) {
return htmlentities(strip_tags(mysql_real_escape_string($data)));
}
?>
users.php
<?php
function user_exists($username) {
$username = sanitize($username);
return (mysql_result(mysqli_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'"), 0) == 1) ? true : false;
}
function user_active($username) {
$username = sanitize($username);
return (mysqli_result(mysqli_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND active = 1"), 0) == 1) ? true : false;
}
function user_id_from_username($username) {
$username = sanitize($username);
return mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"), 0, 'user_id');
}
function login($username, $password) {
$user_id = user_id_from_username($username);
$username = sanitize($username);
$password = md5($password);
return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"), 0) == 1) ? $user_id : false;
}
?>
Любая помощь будет потрясающей!
Access denied for user ''@'web83.local.one.com'
Вы пытаетесь войти без указания пользователя MySQL.
И попробуйте использовать PDO, mysql устарела
Вы можете использовать параметризованные запросы вместо очистки входных данных. Это будет хорошей практикой, если вы используете bcrypt
вместо md5