检查用户名是否已在mysql中存在的php写法
(编辑:jimmy 日期: 2024/11/19 浏览:3 次 )
在写注册系统时,如果要检查用户名是否存在,php可以这样写:
复制代码 代码如下:
$username=$_REQUEST['username'];
$password=$_REQUEST['password'];
echo "<br/>excute the insertUserInfo";
$con=mysqli_connect("localhost","root","","my_db");
$sql="SELECT * FROM user WHERE username='$username'";
ho "<br/>this username aready exists"; } else { $sql="INSERT INTO user (username,password) VALUES ('$username','$password')"; if(!mysqli_query($con,$sql)) { echo "<br/>Error".mysqli_error($con); } else { echo "<br/>one record added"; } }
建议不要用:
复制代码 代码如下:
mysql_num_rows($result)</pre>
lt;pre name="code" class="html"></pre>
复制代码 代码如下:
$username=$_REQUEST['username'];
$password=$_REQUEST['password'];
echo "<br/>excute the insertUserInfo";
$con=mysqli_connect("localhost","root","","my_db");
$sql="SELECT * FROM user WHERE username='$username'";
ho "<br/>this username aready exists"; } else { $sql="INSERT INTO user (username,password) VALUES ('$username','$password')"; if(!mysqli_query($con,$sql)) { echo "<br/>Error".mysqli_error($con); } else { echo "<br/>one record added"; } }
建议不要用:
复制代码 代码如下:
mysql_num_rows($result)</pre>
lt;pre name="code" class="html"></pre>
下一篇:php设计模式之单例模式使用示例