V
V
V012020-05-01 14:46:52
PHP
V01, 2020-05-01 14:46:52

In the php code, there is such an error Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean, what should I do?

<?php

$login=filter_var(trim($_POST['login']),FILTER_SANITIZE_STRING);
$password=filter_var(trim($_POST['password']),FILTER_SANITIZE_STRING);

if(mb_strlen($login)<5 || mb_strlen($login) > 90)
{
$error= "Invalid login length (from 5 to 15 characters).";


}
else if(mb_strlen($password)<5 || mb_strlen($password) > 15)
{
$error= "Invalid password length (from 5 to 15 characters).";


}
else if(!preg_match("/^[a-zA-Z0-9]+$/",$_POST['login']))
{
$error= "Login can only contain English letters and numbers." ;


}

$mysqli= mysqli_connect(
"
if(mysqli_connect_errno())
{

echo "Failed to connect to mysqli:" .mysqli_connect_error();
}
$SQL = "SELECT * FROM `users` WHERE `login`='$login' and `password = md5('$password')";
$res = mysqli_query($mysqli, $SQL) ;

if(!$res)
$error= 'Request failed';

$row = mysqli_fetch_assoc($res);
if($row)
{
$is_authorized = True;
}
else{
$error= 'Invalid login/password pair';
}

if(empty($is_authorized))
include 'forma.php';
else{
echo "You have successfully logged in";
}

?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nokimaro, 2020-05-01
@nokimaro

$SQL = "SELECT * FROM `users` WHERE `login`='$login' and `password` = '".md5($password)."' ";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question