Check whether the username is written in php that already exists in mysql.
Source: Internet
Author: User
There are many methods to check whether the user name already exists in mysql. The following describes how to use php to write the registration system. if you want to check whether the user name exists, php can write as follows:
The code is as follows:
$ Username = $ _ REQUEST ['username'];
$ Password = $ _ REQUEST ['password'];
Echo"
Excute the insertUserInfo ";
$ Con = mysqli_connect ("localhost", "root", "", "my_db ");
$ SQL = "SELECT * FROM user WHERE username = '$ username '";
Ho"
This username aready exists ";} else {$ SQL =" INSERT INTO user (username, password) VALUES ('$ username',' $ password') "; if (! Mysqli_query ($ con, $ SQL) {echo"
Error ". mysqli_error ($ con);} else {echo"
One record added ";}}
Do not use:
The code is as follows:
Mysql_num_rows ($ result)
Lt; pre name = "code" class = "html">
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.