且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查数据库MySQL PHP中是否存在用户名

更新时间:2023-11-29 20:35:10

您可以使数据库中的用户名字段成为主键或唯一,这保证了数据库中的用户名唯一性。

You can make the username field in the database a primary key or unique, which guarantees the username uniqueness in the database.

然后,如果您尝试插入已存在的用户名 mysql_query()函数将失败,返回FALSE

Then, if you try to insert an already existing username the mysql_query() function will fail, returning FALSE.

应该总是使用一个简单的select语句查询数据库中是否存在用户名:

Besides that, you should always query the database for the existence of the username, using a simple select statement:

SELECT username FROM table WHERE username ='$ php_username_var' ;