我正在使用php创建一个网页,代码中没有php错误,但是当我点击按钮时,它没有对页面做任何事情。我不知道发生了什么,如果有人能提供帮助,那将非常感谢。
<?php
session_start();
if( isset($_SESSION['user_id']) ){
header("Location: /");
}
require 'database.php';
if (!empty($_POST['username']) && !empty($_POST['password'])):
$records=$conn->prepare('select id, username, password from admin where username = :username');
$records->bindParam(':username', $_POST['username']);
$records->execute();
$results=$records->fetch(PDO::FETCH_ASSOC);
$message='';
if(count($results)>0 && password_verify($_POST['password'], $results['password'])){
$_SESSION['user_id']=$results['id'];
header("Location: /");
}else{
echo 'Sorry, wrong password';
}
endif;
?>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet' type='text/css'>
<title>Admin Login</title>
</head>
<body>
<?php if(!empty($message)): ?>
<p><?=$message ?></p>
<?php endif; ?>
<h1>Admin Login</h1>
<form id='login' method='POST' action='login.php'>
<label>
Username:
<input type='text' name='username' placeholder='Enter your usename' id='username' size='20' maxlength='100'>
</label>
<br>
<label>
Password:
<input type='password' name='password' placeholder='Enter your password' id='password' size='20' maxlength='100' >
</label>
<br>
<button type='button'>Login</button>
</form>
<a href="register.php">Register</a>
<br/>
<style type='text/css'>
form{
font-family: Verdana;
width: auto;
text-align: center;
}
label {
width: 150px;
font-size: 170%;
length: 200px;
}
body{
background-color: lightblue;
text-align: center;
position: fixed;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -200px;
height:200px;
width:400px;
}
button{
padding:10px;
color:#fff;
background:#0098cb;
width:200px;
margin:20px auto;
margin-top:0px;
border:0px;
border-radius: 3px;
cursor:pointer;
}
input[type='text']{
height:30px;
outline:none;
padding:10px;
width:200px;
border-radius: 3px;
border:1px solid #eee;
margin:20px auto;
}
button:hover{
background:#00b8eb;
}
</body>
</html>