Home  >  Article  >  Backend Development  >  How to check whether the username already exists in mysql in php_PHP tutorial

How to check whether the username already exists in mysql in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:40:39916browse

When writing the registration system, if you want to check whether the user name exists, PHP can write like this:

Copy code 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"; } }

It is recommended not to use:
Copy code The code is as follows:

mysql_num_rows($result)
lt;pre name="code" class ="html">

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/718603.htmlTechArticleWhen writing the registration system, if you want to check whether the user name exists, PHP can write like this: Copy the code as follows: $username=$_REQUEST['username']; $password=$_REQUEST['password']; ech...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn