This question already has an answer here:
- check if row exists with mysql 3 answers
I want to show a message in side or around that the username already exists when the user goes to add the password for the account regsitration where the user chooses an already used username in the registration form itself. I searched the stackoverflow, and all had different languages being used for this. I am doing this in localhost.
This is the code:
<tr>
<td>Username</td>
<td><input type="text" name="Username" required/></td>
</tr>
<tr><td><br></td></tr>
<tr>
<td>Password</td>
<td><input type="password" name="UPass" required/></td>
</tr>
<tr><td><br></td></tr>
<tr>
<td height="29"><input type="submit" value="Register"/></td>
</tr>
<tr><td><br></td></tr>
</table>
</form>
The form name is: AddUser.php Method used is: POST The username table is: Tbl_UserLogin The column name is: Username
Please ask if any more details are required for this. Thank You in advance for any help.
Edit:
I have added a procedure to check whether the username exists already. But that is done only after clicking submit button. And also, the user have to re-enter the data from the start in the registration form.
The procedure I use in DB is:
USE [db_events]
GO
/****** Object: StoredProcedure [dbo].[sp_userregistration] Script Date: 06/26/2016 20:20:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_userregistration]
@Namep varchar(100),
@Mobp varchar(15),
@Emailp varchar(100),
@CNamep varchar(100),
@Rolep int,
@Usernamep varchar(100),
@Passp varchar(100)
AS
BEGIN
declare
@msg varchar(100),
@logidp int,
@cnt int
SET NOCOUNT ON;
begin try
begin transaction
select @cnt=COUNT(*) from Tbl_UserLogin where Username=@Usernamep
if(@cnt=0)
begin
insert into Tbl_UserLogin(RoleId,Username,Password) values(@Rolep,@usernamep,@Passp)
select @logidp=MAX(LogId) from Tbl_UserLogin
insert into Tbl_UserReg(LogId,Name,Mob,Email,CName) values(@logidp,@Namep,@Mobp,@Emailp,@CNamep)
set @msg='Successufully Registered'
end
else
set @msg='Username already in use'
commit
end try
begin catch
rollback
set @msg='Error'
END CATCH
select @msg as message
END
Please do help by showing where to make do the change, as I am a noob in programming.
Thank You
Aucun commentaire:
Enregistrer un commentaire