M
M
Max Pleshkov2016-01-17 16:23:08
PHP
Max Pleshkov, 2016-01-17 16:23:08

Empty result mysqli_query($link,$query), where to look?

What's wrong?
In the php file on the server, the following code is
$query = "SELECT * FROM users WHERE `username`= '$username_login' LIMIT 1";
$result = mysqli_query($link,$query);
$result is empty. Generally empty.
If you insert the query itself in phpmyadmin in sql, it finds the data in the table.
Through the server does not want.
Earlier, about a month ago, everything worked with a bang. I didn't change the server settings.
How to fix?
Thanks...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Nemiro, 2016-01-17
@AlekseyNemiro

You can get information about errors when working with MySql using the mysqli_error function .
What happens if you remove the condition and make the following request:
If the request succeeds, then the problem is probably in the value of the $username_login variable .
Passing values ​​from variables directly to the query text is not recommended. It is better to pass through parameters, or at least escape potentially dangerous characters.
If there are no results, then you need to check the connection string and the success of the connection to the database. You can check for connection errors using the mysqli_connect_error function :

$link = mysqli_connect("localhost", "имя пользователя", "пароль", "имя базы");

if (!$link)
{
    echo mysqli_connect_error();
}

W
winbackgo, 2016-01-17
@winbackgo

And $username_login is $_POST['username_login']? Is the data of this variable escaped? Perhaps the mysqli_error function will help you.

M
Max Pleshkov, 2016-01-17
@zzWerOk

mysqli_error = empty. Those. no errors (from the documentation)
"SELECT * FROM users LIMIT 1" - just as empty as in the first query.
and how to understand it? hmm..
solved the problem.
Hoster changed host to database. I checked the online help and everything worked as before.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question