Home > Backend Development > PHP Problem > php query if user exists

php query if user exists

angryTom
Release: 2023-02-27 22:54:01
Original
5356 people have browsed it

php query if user exists

php query whether the user exists

First get the user name through $_GET["username"]; then use mysqli connects to the database and uses query to query the database; if the query result is greater than 0, the user exists, otherwise the user does not exist.

<?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 =&#39;{$username}&#39; and password = &#39;{$password}&#39;"); //查询数据库中的用户名和密码 并返回集合
$sql = $conn->query("select username from user where username =&#39;{$username}&#39;");
$row = mysqli_fetch_assoc($sql); //取其中一行
if ($row > 0) { //判断是否存在
echo "{$username}用户存在";
} else {
echo "{$username}用户不存在";
}
?>
Copy after login

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of php query if user exists. For more information, please follow other related articles on the PHP Chinese website!

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template