L
L
luidgiii2020-01-13 03:08:45
PHP
luidgiii, 2020-01-13 03:08:45

The query removes two rows instead of one. What is the reason?

Greetings. Tell me what could be the problem?

$mysqli = new mysqli ("localhost", "mysql", "mysql", "dbname");
    $mysqli->query ("SET NAMES 'utf8'"); 

$query = $mysqli->query("SELECT `id`, `country1`, `country2`, `id_country` FROM countries");
$data = $query->fetch_assoc();

$del = $mysqli->query("DELETE FROM `countries` WHERE `id` = '$data[id]'");

If the same query is executed via phpmyadmin, it deletes one line.
$del = $mysqli->query("DELETE FROM `countries` LIMIT 1'");

This option similarly catches 2 lines ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arman, 2020-01-13
@luidgiii

I suspect the requests go by the GET method and there is no favicon.ico file (some browsers ask for it by default for the tab), it turns out there are two requests that delete records in turn. In phpmyadmin, actions go by the POST method, so there is no problem even if you delete this file
Check with the browser inspector what requests go to the page with this code

F
FanatPHP, 2020-01-13
@FanatPHP

The question is some kind of nonsense.
The php code selects a random entry and then deletes it.
If the code deletes a random string during any access to the site, then the database will always be empty.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question