You must Sign In to post a response.
  • Category: General

    How To Generate and Save Auto Increment UserId with Prefix using Php Mysql

    Hi Developers,

    I need to generate unique auto increment user id with Prefix in Php
    and also save it to the database.
    ]My required Output is like EMP001,EMP002,EMP001.......................... to EMP00n n numbers
    This is the first step in my project
    i don't know php is well.

    so please help me to generate unique id using php code and also save it into the database.

    Thanks with
  • #767454
    If the prefix "EMP" is constant, you can simple concatenate "EMP" with auto generate user id.
    I am not familiar with PHP. Is it very complex in PHP?.

    If you are nor familiar with PHP do not directly jump into the project. First read some good tutorials then start your project.

    By Nathan
    Direction is important than speed

  • #767455
    Ok nathan thanks for your quick reply


  • #767485

    You can do this in 2 ways, one is AutoIncrement the field while creating table itself and another one is increment the field value while insert the record.


    CREATE TABLE [dbo].[Employee](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [EmpNo] AS ([PreFix]+ RIGHT('0000000' + CAST(Id AS VARCHAR(7)), 7)) PERSISTED,


    SELECT @EmpNo = @PreFix + RIGHT('0000000' + CAST(@Id AS VARCHAR(7)), 7)
    --use the above EmpNo while insert it into database

    Hope this will helpful to you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • Sign In to post your comments