Hi, I'm creating a stored procedure for user registration. My stored procedure:
delimiter //
drop procedure if exists sp_insertar_usuario;
create procedure sp_insertar_usuario
(
in idpersona int,
in usuario varchar(20),
in pass varchar(45),
in imagen varchar(400),
in email varchar(45)
)
begin
insert into seg_usuario(perso_id, usu_nom, usu_pass, usu_imagen, usu_freg, usu_est, usu_email)
values(idpersona, usuario, pass, imagen,now(),"Activo",email);
end //
delimiter ;
Everything works normal, the idea is that before doing the insert the procedure verifies if the idperson that is going to be used has already been used with another user. I was thinking something like this:
begin
set @resp = select count(*) from segu_usuario where perso_id = idpersona;
if @resp > 0 then
select 'REPETIDO'
else
insert into seg_usuario(perso_id, usu_nom, usu_pass, usu_imagen, usu_freg, usu_est, usu_email)
values(idpersona, usuario, pass, imagen,now(),"Activo",email);
select 'OK'
end if;
end //
But the procedure is not created. Any solution, or alternative? I thank you in advance.