Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have this procedure: (DDL code extracted directly from MySQL Workbench just to make sure)

SQL
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `removerContacto`(nome VARCHAR(250),id INT)
BEGIN
DELETE FROM Contactos WHERE Nome = nome AND UsersID = id;
END



and I call it this way:

mysql_query("CALL removerContacto('".$_GET['nome']."','".$_GET['uid']."')");


The problem is removing all rows instead only one (there's only for that WHERE clause). If I try

mysql_query("DELETE FROM Contactos WHERE Nome ='".$_GET['nome']."' AND UsersID=".$_GET['uid']."");


or directly at workbench

DELETE FROM Contactos WHERE Nome = 'someone' AND UsersID = 1;


It works correctly. What am I doing wrong?
Posted

I would make sure that the procedure parameters do not have the same names as table columns - because variables are case insensitive, Nome = nome will always be true.
 
Share this answer
 
Comments
Maxdd 7 21-Apr-11 16:19pm    
Accepted! Thank you very much I didnt know that :)
The fuirst thing I'd do is make sure that $_GET['nome'] and $_Get['uid] actually contained what you're expecting them to contain.
 
Share this answer
 
Comments
Maxdd 7 21-Apr-11 16:16pm    
Of course. I did that. I didnt said that because I said mysql_query with hardcoded SQL statement worked, but of course I did echo $_GET['nome'].$_GET['uid'];
I suspect there is something wrong on userid and name .
How this is possible to table have a multiple record for same userid and for same username ?
Bye the way I tried this in my Mysql Query Browser 5.0 . It works fine.

It is very helpful for me if you could share the table structure of Contactos .
 
Share this answer
 
Comments
Maxdd 7 21-Apr-11 16:19pm    
It's not possible because one of the fields it's primary key.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900