当前位置: 编程技术>php
检查用户名是否已在mysql中存在的php写法
来源: 互联网 发布时间:2014-08-26
本文导语: 在写注册系统时,如果要检查用户名是否存在,php可以这样写: 代码如下: $username=$_REQUEST['username']; $password=$_REQUEST['password']; echo "excute the insertUserInfo"; $con=mysqli_connect("localhost","root","","my_db"); $sql="SELECT * FROM user WHERE username='$use...
在写注册系统时,如果要检查用户名是否存在,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 name="code" class="html">
代码如下:
$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 name="code" class="html">