A
A
Andrey Samoylenko2020-04-23 15:20:31
PHP
Andrey Samoylenko, 2020-04-23 15:20:31

Why is mysqli_query not executing?

Why does mysqli_query return false ? I tried to insert the request directly into phpMyAdmin - no errors! Everything is entered.

<?php

    	$link = mysqli_connect("localhost", "*******", "*******");
        if ($link == false) {
        	echo("Ошибка подключения");
        } else {
            $sql = 'INSERT INTO players SET age = 11';
            $result = mysqli_query($link, $sql);
            if ($result == false) {
            	echo("Ошибка при выполнении запроса");
            } else {
            	echo("Данные успешно добавлены");
            }

        }
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2020-04-23
@Ketch

Probably because you need to pass 4 parameters:

$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db")

F
FanatPHP, 2020-04-23
@FanatPHP

Because it is necessary to write not abstract reasoning, "You have an ashypka!" and then guessing with a finger to the sky, and asking the database what specifically it doesn’t like. And she writes everything herself.

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect("localhost", "*******", "*******");
$mysqli->set_charset("utf8mb4");

$sql = 'INSERT INTO players SET age = 11';
$result = mysqli_query($link, $sql);
echo "Данные успешно добавлены";

And after receiving the error message, it will be possible to read and correct it yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question