Check to see if the user name already exists in mysql
- 2020-12-18 01:46:17
- OfStack
When writing to the registration system, if you want to check if the user name exists, php can write like this:
Don't use:
$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"; } }
Don't use:
mysql_num_rows($result)</pre>
lt;pre name="code" class="html"></pre>