Answer the question
In order to leave comments, you need to log in
How to check authorization data through MySQL?
I want to check by login and password for authorization through MySQL
In Google, almost everything is done through a condition with a function that determines the number
of the same logins and passwords, but as I understand it, php has changed something in the function.
Couldn't find it through the documentation. The question is what, how and through
what now you need to check the data through MySQL? In my case, this is the username and password.
Mistake:
Fatal error: Uncaught TypeError: mysqli_num_rows(): Argument #1 ($result) must be of type mysqli_result, bool given in
if (mysqli_num_rows($checkUser) > 0)
Answer the question
In order to leave comments, you need to log in
mysqli_query returns false if an error occurred while executing the query. Therefore, if you are already writing in this style, then please check that no error occurred during the execution of the request. More or less like this:
$checkUser = mysqli_query($connect, "SELECT * FROM `users` WHERE `email` == '$email' AND `password` == '$password'");
if ($checkUser === false) {
die(mysqli_error($connect));
}
// БЕЗОПАСНО выполняем запрос
$stmt = $link->prepare("SELECT * FROM comments WHERE art_id = ?");
$stmt->bind_param("s", $note_id);
$stmt->execute();
// получаем данные
$result = $stmt->get_result();
$comments = $result->fetch_all(MYSQLI_ASSOC);
<?php if ($comments): ?>
<?php foreach ($comments as $row): ?>
<?=$row['comment']?><br>
<?php endforeach ?>
<?php else: ?>
Эту запись еще никто не комментировал
<?php endif ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question