Php 登录页面的验证检查不工作
我正在使用Php 登录页面的验证检查不工作,php,html,verification,Php,Html,Verification,我正在使用php为一个辅助项目进行登录验证。现在我有一个用户是admin,密码就是123。如果用户输入了错误的密码或用户名,它将抛出一条消息,说明错误的密码或错误的用户名。目前两者都不行,我正试图找出原因。我将在下面发布html和php 更新:我添加了方法=post。不知道从这里到哪里去 <?php $uname = $_POST['uname']; $passwd = $_POST['psw']; $error = ""; $success =""; if(isset($_POST['
php
为一个辅助项目进行登录验证。现在我有一个用户是admin
,密码就是123
。如果用户输入了错误的密码或用户名,它将抛出一条消息,说明错误的密码
或错误的用户名
。目前两者都不行,我正试图找出原因。我将在下面发布html
和php
更新:我添加了方法=post
。不知道从这里到哪里去
<?php
$uname = $_POST['uname'];
$passwd = $_POST['psw'];
$error = "";
$success ="";
if(isset($_POST['submit'])){
if($uname == 'admin'){
if($passwd == '123'){
$error = "";
$success = "Welcome Admin";
}
else{
$error = " Wrong Password!!";
$success = "";
}
}
else{
$error = " Wrong Username!";
$success = "";
}
}
?>
<html lang="en">
<head>
<title>Hangman Home Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-
width, initial-scale=1">
<link rel="stylesheet" type="text/css"
href="home.css">
</head>
<body>
<div class="header">
<div class="a">Hangman</div>
<br>
<br>
<br>
<!--column start here -->
<div class="hi">
<table id="leader">
<tr>
<th><img src="crown.gif"></th>
</tr>
<tr>
<td>Leader Board</td>
</tr>
<tr>
<td>1st. John : 4 guess</td>
</tr>
<tr>
<td>2nd. Smith : 6 Guesses</td>
</tr>
<tr>
<td>3rd. Tom : 7 Guesses</td>
</tr>
<tr>
<td>4th. Allen : 8 Guesses</td>
</tr>
</table>
</div>
<!-- form start here -->
<br><br>
<div class="b">Think You Can Beat #1 ?</div>
<center><button
onclick=
"document.getElementById('id01').
style.display='block'"
style="width:auto;">Play Now!!!
</button></center>
<div id="id01" class="modal">
<form class="modal-content animate" action="/action_page.php">
<div class="imgcontainer">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span>
<img src="hang1.gif" alt="logo" class="avatar">
</div>
<div class="container">
<p class="error">
<?php echo 'error'; ?>
</p>
<p class="success">
<?php echo 'success'; ?>
</p>
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
<label>
<input type="checkbox" checked="checked" name="remember"> Remember me
</label>
</div>
<div class="container" style="background-color:#f1f1f1">
<button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button>
<span class="psw">Forgot <a href="#">password?</a></span>
</div>
</form>
刽子手主页
刽子手
领导委员会
第一。约翰:猜猜看
第二。史密斯:6次猜测
三,。汤姆:猜7次
第四。艾伦:8次猜测
你认为你能打败1吗?
现在就玩吧!!!
&时代;
用户名
密码
登录
记得我吗
取消
忘记
您正在回显一个名为success and error的字符串
您应该做的是回显变量:
<?php echo $error; ?>
以及:
您正在回显一个名为success and error的字符串
您应该做的是回显变量:
<?php echo $error; ?>
以及:
您的脚本有一些错误。首先,让我们检查一下您的表格:
<form action="/action_page.php">
<input type="text" placeholder="Enter Username" name="uname" required>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
<input type="checkbox" checked="checked" name="remember"> Remember me
</form>
登录
记得我吗
填写并提交此代码后,将在PHP脚本中生成以下变量:
$\u GET[“uname”]、$\u GET[“psw”]和$\u GET[“记住”]。
您试图使用$\u POST
访问数据,但只有在标记处添加属性method=“POST”时才会发生这种情况
您还可以使用$\u请求
访问混合的$\u GET
和$\u POST
数组
另一个错误是检查数据是否已在代码顶部提交的方式。没有变量$\u POST[“submit”]
(既没有变量$\u GET[“submit”]
也没有变量$\u REQUEST[“submit”]
),因为表单中没有具有此名称的变量,您可能正在考虑提交按钮。要检查表单是否已提交,最好的方法是检查用户名和密码是否为空
此外,您在表单中回显“error”和“success”,并且可能试图回显$error和$success的结果。您的脚本中有一些错误。首先,让我们检查一下您的表格:
<form action="/action_page.php">
<input type="text" placeholder="Enter Username" name="uname" required>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
<input type="checkbox" checked="checked" name="remember"> Remember me
</form>
登录
记得我吗
填写并提交此代码后,将在PHP脚本中生成以下变量:
$\u GET[“uname”]、$\u GET[“psw”]和$\u GET[“记住”]。
您试图使用$\u POST
访问数据,但只有在标记处添加属性method=“POST”时才会发生这种情况
您还可以使用$\u请求
访问混合的$\u GET
和$\u POST
数组
另一个错误是检查数据是否已在代码顶部提交的方式。没有变量$\u POST[“submit”]
(既没有变量$\u GET[“submit”]
也没有变量$\u REQUEST[“submit”]
),因为表单中没有具有此名称的变量,您可能正在考虑提交按钮。要检查表单是否已提交,最好的方法是检查用户名和密码是否为空
此外,您在表单中回显“error”和“success”,并且可能试图回显$error和$success的结果。因为您既不显示错误消息,也不显示成功消息。下面是解决您的问题的代码:
..............
<!-- in your form tag add attribute method="POST" -->
<!-- Your code -->
<!-- in your div class="container"> -->
<?php if($success) { ?>
<p class="success"><?php echo $success; ?></p>
<?php } else if ($error) { ?>
<p class="error">
<?php echo $error; ?>
</p>
。。。。。。。。。。。。。。
快乐编码;)
因为您既不显示错误消息也不显示成功消息。下面是解决您的问题的代码:
..............
<!-- in your form tag add attribute method="POST" -->
<!-- Your code -->
<!-- in your div class="container"> -->
<?php if($success) { ?>
<p class="success"><?php echo $success; ?></p>
<?php } else if ($error) { ?>
<p class="error">
<?php echo $error; ?>
</p>
。。。。。。。。。。。。。。
快乐编码;)
你有什么办法可以帮我起步吗。我是php新手,在这方面已经有相当长的一段时间了。我认为学习基本php的最好方法是从官方php手册()中学习,这些注释是解决方案的重要来源。你也可以在()上阅读快速的“简介教程”。有什么方法可以帮助我开始学习吗。我是php新手,在这方面已经有相当长的一段时间了。我认为学习基本php的最好方法是从官方php手册()中学习,这些注释是解决方案的重要来源。您还可以在()上阅读快速的“简介教程”。