C
C
Cesar12018-03-07 22:05:37
PHP
Cesar1, 2018-03-07 22:05:37

What is the reason for the fetch_assoc() error?

$servername = 'localhost';
$username = 'root';
$password = '';
$dbname = '1';
$mysqli = new mysqli($servername, $username, $password, $dbname);
$login = $_POST["login"];
$password = $_POST["password"];
$nick = $mysqli->query("SELECT * FROM 'accounts'");
$result = $nick->fetch_assoc();
var_dump( $result );
Throws an error: "Fatal error: Uncaught Error: Call to a member function fetch_assoc()"

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
Boris Syomov, 2018-03-07
@Cesar1

With the fact that the request is not correct - '' around the table name is not in place. And in the end, you returned FALSE, not mysqli_result.
Besides, it is better to use PDO.

A
Arman, 2018-03-07
@Arik

query
can return false, you do not have a check for this and you suffer from showing an error, and the error is most likely that you need to use apostrophes (`) for the names of tables and fields, and quotes for text. You have the name of the table in quotation marks, i.e. need`accounts`

R
ralliart, 2018-03-07
@ralliart

Try procedural style first

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question