Home > Article > Backend Development > php verify name exists in mysql
#How does php verify whether the name exists in mysql?
PHP connects to MySQL to query whether the user name exists (login verification)
The code is as follows:
<?php header("Content-Type:text/html;charset=utf8"); $username = $_GET["username"]; //获取输入用户名 $password = $_GET["password"]; //获取输入密码 $mysql_server_name = "localhost:3306"; //连接数据库端口 $mysql_username = "root"; //用户名 $mysql_password = "123456"; //密码 $mysql_database = "test"; //数据库名称 $conn = new mysqli($mysql_server_name, $mysql_username, $mysql_password, $mysql_database); //构造函数mysql $sql = $conn->query("select username from user where username ='{$username}' and password = '{$password}'"); //查询数据库中的用户名和密码 并返回集合 $row = mysqli_fetch_assoc($sql); //取其中一行 if ($row > 0) { //判断是否存在 echo "欢迎'{$username}'再次登录"; } else { echo ",您还没有账号,请先进行注册!!!"; header("location:register.html"); //跳转至注册页面 } ?>
For more PHP knowledge, please visit PHP中文网!
The above is the detailed content of php verify name exists in mysql. For more information, please follow other related articles on the PHP Chinese website!