我的网站又遇到了一个问题,我无法解决。
我试图使它这样当管理员登录时,他将被带到管理页面,但由于某种原因,当我输入正确的详细信息到登录,并按下提交按钮,它只是带我回到管理登录页面再次。
这是我的问题所在
https://gyazo.com/34f133fea4b20ec285ee7ff491053145
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="UTF-8">
<title>Login</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js" type="text/javascript"></script>
<link href='https://fonts.googleapis.com/css?family=Ubuntu:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/148866/reset.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<body>
<main id="cd-main-content">
<section id="cd-intro">
<h1>Admin Log In</h1>
<header class="cd-header">
<?php
require('db.php');
session_start();
// If form submitted, insert values into the database.
if (isset($_POST['username'])){
// removes backslashes
$adminusername = stripslashes($_REQUEST['adminusername']);
//escapes special characters in a string
$adminusername = mysqli_real_escape_string($con,$adminusername);
$adminpassword = stripslashes($_REQUEST['adminpassword']);
$adminpassword = mysqli_real_escape_string($con,$adminpassword);
//Checking is user existing in the database or not
$query = "SELECT * FROM `admin` WHERE username='$adminusername'
and password='".md5($adminpassword)."'";
$result = mysqli_query($con,$query) or die(mysql_error());
$rows = mysqli_num_rows($result);
if($rows==1){
$_SESSION['username'] = $adminusername;
// Redirect user to admin page /////////////////////////////////////////////////////////////////////
header("Location: adminpage.php");
}else{
echo "<div class='form'>
<h3>Username/password is incorrect.</h3>
<br/>Click here to <a href='admin.php'>Login</a></div>";
}
}else{
?>
<div class="form">
<form action="" method="post" name="login">
<input type="text" name="adminusername" placeholder="Username" required />
<input type="password" name="adminpassword" placeholder="Password" required />
<input name="submit" type="submit" value="Login" />
</form>
</div>
<?php } ?>
<a class="cd-menu-trigger" href="#main-nav">Menu<span></span></a>
</header>
<div class="cd-blurred-bg"></div>
</section> <!-- cd-intro -->
</main>
<div class="cd-shadow-layer"></div>
<nav id="main-nav">
<ul>
<li><a href="#0"><span>Login</span></a></li>
<li><a href="#0"><span>What's On</span></a></li>
<li><a href="#0"><span>Favourites</span></a></li>
<li><a href="#0"><span>About</span></a></li>
<li><a href="admin.php"><span>Admin</span></a></li>
</ul>
<a href="#0" class="cd-close-menu">Close<span></span></a>
</nav>
</body>
<script src='js/jquery.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>
3条答案
按热度按时间83qze16e1#
你在做:
试试这个
作为说明,我建议您尝试使用一个框架,比如laravel。
toe950272#
试试这个:-
ruyhziif3#
首先,我将通过var\u dump($\u post)进行调试,看看您得到了什么。我敢打赌,因为您没有为输入值name设置id,所以它不起作用。如果任何检查isset($\u post['username'])的操作都不起作用,因为您没有该名称的VARIABLE集合。
var\u dump($\u post)并查看您得到了什么。如果没有,则在输入中添加id='username'