为用户在Mysql数据库中注册时生成唯一id

时间:2022-11-25 13:12:38

I am trying to create a login-registration system with PHP mysql and HTML. I want that, when user will register with his email and password, an unique ID will generate into database only for him. Example: when a user register an unique number auto create like 1, 2, 3, 4... I want an unique ID of 5 digits instead of 1, 2, 3 auto increment number. 为用户在Mysql数据库中注册时生成唯一id 为用户在Mysql数据库中注册时生成唯一id

我正在尝试用PHP mysql和HTML创建一个登录注册系统。我希望,当用户注册他的电子邮件和密码时,一个唯一的ID只会为他生成到数据库中。示例:当用户注册一个独特的数字自动创建时,如1、2、3、4……我想要一个5位数的唯一ID,而不是1 2 3个自动递增的数字。

6 个解决方案

#1


1  

Make your id (primary) column auto-increment.

使您的id(主)列自动递增。

Also, add a record with id 10000 either manually or with code.

另外,手动或代码添加id 10000的记录。

Next record added will have id 10001.

下一个新增记录将是id 10001。

This solves your question.

这解决了你的问题。

#2


1  

To start with an AUTO_INCREMENT value other than 1, set that value with CREATE TABLE or ALTER TABLE, like this:

若要从1以外的AUTO_INCREMENT值开始,请将该值设置为CREATE TABLE或ALTER TABLE,如下所示:

  ALTER TABLE tbl AUTO_INCREMENT = 100000;

#3


1  

You can define auto increment value when you create table.

您可以在创建表时定义自动增量值。

Fist make that field primary key and assign auto increment value to your desire number.

首先将该字段设置为主键并将自动增量值赋给您的期望编号。

CREATE TABLE IF NOT EXISTS tableName (
  id int(11) NOT NULL PRIMARY KEY,
  .........
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8;

#4


1  

I hope you need to do this with your phpmyadmin UI. So go to phpmyadmin and follow the steps below.
(If you have already selected autoincrement field start from step 4).

1. In "Structure" tab of your table
2. Click on edit on column you want auto_increment
3. under "Extra" tab choose "auto_increment"
4. then go to "Operations" tab of your table
5. Look for "Table options" -> auto_increment Then type 10000

我希望你需要用你的phpadmin myui做这个。因此,访问phpmyadmin并遵循以下步骤。(如果您已经选择了从步骤4开始的自动递增字段)。在表2的“结构”选项卡中。单击想要auto_increment 3上的edit。在“额外”选项卡下选择“auto_increment”4。然后切换到表5的“操作”选项卡。查找“表选项”-> auto_increment然后键入10000。

#5


0  

You can disable the auto increment and use uniqid() function then save it in the ID Section.

您可以禁用自动增量并使用uniqid()函数,然后将其保存在ID部分。

#6


0  

For this you can use ZEROFILL it will prepand required 0's to number so try this query:

为此,您可以使用ZEROFILL它将prepand要求0进行编号,因此可以尝试以下查询:

ALTER TABLE `tbl_teacher` CHANGE `id` `id` INT(11) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT;

;)

,)

#1


1  

Make your id (primary) column auto-increment.

使您的id(主)列自动递增。

Also, add a record with id 10000 either manually or with code.

另外,手动或代码添加id 10000的记录。

Next record added will have id 10001.

下一个新增记录将是id 10001。

This solves your question.

这解决了你的问题。

#2


1  

To start with an AUTO_INCREMENT value other than 1, set that value with CREATE TABLE or ALTER TABLE, like this:

若要从1以外的AUTO_INCREMENT值开始,请将该值设置为CREATE TABLE或ALTER TABLE,如下所示:

  ALTER TABLE tbl AUTO_INCREMENT = 100000;

#3


1  

You can define auto increment value when you create table.

您可以在创建表时定义自动增量值。

Fist make that field primary key and assign auto increment value to your desire number.

首先将该字段设置为主键并将自动增量值赋给您的期望编号。

CREATE TABLE IF NOT EXISTS tableName (
  id int(11) NOT NULL PRIMARY KEY,
  .........
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8;

#4


1  

I hope you need to do this with your phpmyadmin UI. So go to phpmyadmin and follow the steps below.
(If you have already selected autoincrement field start from step 4).

1. In "Structure" tab of your table
2. Click on edit on column you want auto_increment
3. under "Extra" tab choose "auto_increment"
4. then go to "Operations" tab of your table
5. Look for "Table options" -> auto_increment Then type 10000

我希望你需要用你的phpadmin myui做这个。因此,访问phpmyadmin并遵循以下步骤。(如果您已经选择了从步骤4开始的自动递增字段)。在表2的“结构”选项卡中。单击想要auto_increment 3上的edit。在“额外”选项卡下选择“auto_increment”4。然后切换到表5的“操作”选项卡。查找“表选项”-> auto_increment然后键入10000。

#5


0  

You can disable the auto increment and use uniqid() function then save it in the ID Section.

您可以禁用自动增量并使用uniqid()函数,然后将其保存在ID部分。

#6


0  

For this you can use ZEROFILL it will prepand required 0's to number so try this query:

为此,您可以使用ZEROFILL它将prepand要求0进行编号,因此可以尝试以下查询:

ALTER TABLE `tbl_teacher` CHANGE `id` `id` INT(11) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT;

;)

,)