I have a mysql stored procedure to check if the login information matchs with my database information
obs:I've just started using Mysql, so it may have a lot of errors in this code.
-Table 1 - Funcionario (email_func,senha)
-Table 2 - Cliente (email_cli,senha_cli)
Here's the sp code
delimiter %%
create procedure SpLogin(email varchar(100), senha varchar(15))
begin
declare c int;
declare f int;
begin
if exists(select * from cliente where email_cli = email and senha_cli = md5(senha))
then select 'c' as result;
else set c = 0;
end if;
end;
begin
if exists (select * from funcionario where email_func = email and senha = senha)
then select 'f' as result;
else set f = 0;
end if;
end;
begin
if (f = 0 and c = 0)
then select '0' as result;
end if;
end;
end %%
delimiter ;
There is an 'email' that is the same in the two tables, when I call the sp with this email It always return 'f' as result regardless what 'senha' I write.
You should name your procedure parameters with a different name than the column names in your table.
where ... senha = senha
The column senha
is bound to be equal to the column senha
in the same row.
MySQL doesn't know that you mean the first senha
is the column, and the second senha
is the procedure parameter.