logic problem with my stored procedure
Posted by:
Kevin Jahns
Date: September 12, 2016 01:48PM
I having a logic problem with checkfirstnamecount=0 . This is what I wrote:
DELIMITER go
/* Passing the parameters */
/* I still get firstname error message every time I tried to execute*/
Create procedure registerusers(
Out UserID tinyint(11),
IN iFirstName varchar(30),
IN iLastName varchar(30),
IN iPassword varchar(30),
IN iEmailAddress varchar(30),
IN iSalt varchar(40),
IN iRoleID varchar(1))
BEGIN
/* declaring thecheckfirstnamecount for counting first name*/
declare checkfirstnamecount int;
select count(FirstName) into checkfirstnamecount
from users
where FirstName = iFirstName;
/*checking if the count firstname is not equal to zero */
/* if count 0 is equal to count 0 then it should display an error message*/
If(checkfirstnamecount=0) then
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Fill out the First Name ';
else
insert into users(
/* insert into user if its not empty */
FirstName,
LastName ,
Password ,
EmailAddress ,
Salt ,
RoleID
)
Values
(
iFirstName,
iLastName ,
iPassword ,
iEmailAddress ,
iSalt ,
iRoleID
);
set UserID = last_insert_id();
end if;
End
go
DELIMITER ;
When I tried:
set @new_id = null;
call registerusers(@new_id,'Thomas','Smith','5566','thomas@gmail.com','sdfd','U');
select @new_id;
I got an error message saying: Fill out the First Name. I actually want the data to be insert if its not empty.