所以我是新手并学习PHP,我有一个登录系统应该检查用户名和密码是否与数据库中的匹配,如果是,它会记录用户但是你可以在表单中输入任何内容并记录用户我有一个登录表单,可以带你到这个页面 .
<?php
include 'Connection.php';
session_start();
if (isset($_POST['submit']))
//checking if the user is coming from the form
{
$Username=$_POST['Username'];
$Password=$_POST['Password'];
//$Admin = $_GET['UserType'];
$query="SELECT * FROM Users
WHERE Username = '$Username' AND Password ='$Password' AND UserType ='admin' OR UserType =''";
//checking if theirs a match of username and password
$result=mysqli_query($Connection, $query);
//checking if their is a match
if ($row = mysqli_fetch_assoc($result))
{
$_SESSION['Username'] = $Username.' '.$row['UserType'].'';
$_SESSION['message'] = 'success';
include'Login.php';
//if a match is found
}
else
{
$_SESSION['error']='User not recognised';
header("Location: {$_SERVER['HTTP_REFERER']}");
//if a match isn't found
}
}
else
{
header('location: Home.php');
}
if ($row['UserType'] == 'admin'){
$_SESSION['admin'] = true;
}
?>