Home > php教程 > php手册 > body text

检查用户名是否已在mysql中存在的php写法

WBOY
Release: 2016-06-06 20:25:33
Original
988 people have browsed it

检查用户名是否已在mysql中存在的方法有很多,下面为大家介绍下使用php是如何做到的

在写注册系统时,如果要检查用户名是否存在,,php可以这样写:

复制代码 代码如下:


$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"; } }


建议不要用:

复制代码 代码如下:


mysql_num_rows($result)
lt;pre>

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!