php - MySql error : Result consisted of more than one row

18

I have the error :Result consisted of more than one row but i can't find out it.

The entry id_user has only one record in its table.

The procedure:

CREATE DEFINER=`root`@`localhost` PROCEDURE `delete_user_deep`(id_user int(11))
BEGIN

declare nome_loc varchar(45);
declare cognome_loc varchar(45);

select nome,cognome
into nome_loc,cognome_loc
from user
where id_user=id_user;

delete from Radius.radcheck where username in (
    select mac_address from machine where id_user =id_user);

delete from Radius.radreply where username in (
    select mac_address from machine where id_user =id_user);

delete from machine_ip where id_machine in (
    select id_machine from machine where id_user=id_user);

delete from machine where id_user = id_user;

delete from document where id_user=id_user;

delete from user where id_user=id_user;

insert into log_generic values(
                    NULL,
                    'USER',
                    'Delete User Deep',
                    (select concat ('User: ',id_user,' Name: ',cognome_loc,' Prename: ',nome_loc)),
                    now());

END
374

Answer

Solution:

The problem is in this statement:

select nome,cognome
into nome_loc,cognome_loc
from user
where id_user=id_user;

This will return an error if there is more than one row. The error is documented here.

This is caused because the parameter name is the same as the column name. Theid_user is referring to the column on both sides of the comparison.

The query should look like:

select nome, cognome
into nome_loc, cognome_loc
from user
where id_user = param_id_user;

Always prefix parameter and variable names with something to distinguish them from column names.

People are also looking for solutions to the problem: mysqli - always last database line is deleted when deleting from php page

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.