Php 出现PDO问题的登录页面
我正在使用php创建一个网页,代码中没有php错误,但是当我单击按钮时,它没有对网页做任何操作。我不知道发生了什么,如果有人能帮上忙,那就太好了,谢谢Php 出现PDO问题的登录页面,php,html,Php,Html,我正在使用php创建一个网页,代码中没有php错误,但是当我单击按钮时,它没有对网页做任何操作。我不知道发生了什么,如果有人能帮上忙,那就太好了,谢谢 <?php session_start(); if( isset($_SESSION['user_id']) ){ header("Location: /"); } require 'database.php'; if (!empty($_POST['username']) && !empty($_POST[
<?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>
您的按钮类型是您需要更改提交类型的按钮 您的按钮现在:
<button type='button'>Login</button>
你的按钮应该是什么
<button type='submit' name="btnName">Login</button>
然后在php脚本上检查按钮是否已设置,然后执行处理
<?php
if(isset($_POST['btnName'])){
// then the php code you have
}
?>
按钮类型='Button'与类型='submit'
提交:
该按钮将表单数据提交到服务器。如果未指定属性,或者属性动态更改为空值或无效值,则这是默认值
按钮:
该按钮没有默认行为。它可以具有与元素事件关联的客户端脚本,这些脚本在事件发生时被触发
表单中没有发生任何事件的原因是,如果您有type=按钮,那么您没有与其事件关联的客户端脚本。您的预期密码输入与用户名的密码输入相同,并且按钮类型应为submit typeoh,我已经修复了此部分。没有任何改变。