douangoo48863 2016-09-11 13:02
浏览 365

如何在登录表单上方显示错误的用户名和密码?

can someone help me to display wrong username and password just above the signin form ?? it shouldn't redirect to other page ,rather it must display just above the signin form my code contains

<!Doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="mainpagestyle.css">
</head>
<style>
body {
background:#99ffff;
height:100%;
width:100%;
}

#footer {
poition:absolute;
    padding: 1em;
    color: white;
    background-color: black;
    clear: left;
    text-align: center;
    width: 100%;
   border: 1px solid gray;
    bottom : 0;
   margin-top:90%;

}

</style>
<body>


<div class="container"> 
<h1>"MARK"</h1> 
<ul id="headline" class="fallingtextrotator" style="height:2em"> 
<div class="grad"></div> 
<form action="checkuser-pass.php" method="POST"> 
<div class="header"> 
<div>LOG<span>IN</span> </div> 
</div> 
</br> 
<div class="login"> 
User Name: <input type="text" name="username"><br> 
Password: &nbsp&nbsp <input type="password" name="password"><br><br> 
<input type="submit" name="submit" value="Login!"> 
&nbsp &nbsp &nbsp &nbsp <a href=" ">FORGOT PASSWORD</a></div> 
</div> 
</br> 
</form> 

<ul id="headline" class="fallingtextrotator" style="height:2em"> 
<div class="grad"></div> 
<form action="checkguest.php" method="POST"> 
<div class="headerr"> 
<div>SIGN<span>UP</span> </div> 
</div> 
</BR>

<div class="signup"> 
User Name: <input type="text" name="username"><br><br> 
Email Id:&nbsp&nbsp&nbsp <input type="email" name="emailid"><br> 
Password: &nbsp&nbsp <input type="password" name="password"><br><br> 
<input type="submit" name="submit" value="signup!"> 
</form> 

</div> 
</section> 
<section class="footer"> 
<h5> &#xA9; Navya Chowdary</h5> 
<p><a href="#">Carrers </a>&nbsp &nbsp&nbsp&nbsp<a href="#"> Blog</a> &nbsp 
&nbsp&nbsp&nbsp<a href="#">Bussiness</a> 
&nbsp &nbsp&nbsp&nbsp<a href="#"> About Us</a>&nbsp &nbsp&nbsp&nbsp<a 
href="#">Suggestions or Complaints</a> &nbsp &nbsp&nbsp&nbsp<a href="#">Bug</a> 
</section> 
</body> 

</html>

and here comes my checkuser-pass.php

<?php 
session_start(); 
$host="127.0.0.1"; 
$username="root"; 
$password=""; 
$db="markconnect"; 
$tb="userform"; 
$mysqli = new mysqli($host,$username,$password,$db) or die(mysqli_error());; 
//DEFINE USERNAME AND PASSWORD 
$username=$_POST['username']; 
$password=$_POST['password']; 
//echo md5($password); exit;
// To protect MySQL injection 
$username = stripslashes($username); 
$password = stripslashes($password); 
$username = mysqli_real_escape_string($mysqli,$username); 
$password = mysqli_real_escape_string($mysqli,$password); 
$password = md5($password);
//echo $password; exit;

$sql="SELECT * FROM $tb WHERE username='$username' and password='$password'"; 
//echo $sql; exit;
$result=mysqli_query($mysqli,$sql); 
//43 Mysql_num_row is counting table row 
$count=mysqli_num_rows($result); 
//print_r($count); 

if($count==1){
$_SESSION['username'] = $username;
//include 'saver.php'; 
header("Location: saver.php");
} 

else { 
echo "Wrong Username or Password"; 
//  <p>Please enter both username and password.</p>


} 
ob_end_flush(); 
?>
  • 写回答

1条回答 默认 最新

  • dro62273 2016-09-11 18:14
    关注

    If you want the page with the login form to process the request, you have to put the PHP code from checkuser-pass.php in your form page and to:

    <form action="" method="POST"> 
    

    Then echo "Wrong Username or Password"; can be easily done with the single page form processing.

    onepageformproccesing.php:

    <?php
        if(isset($_POST['submit'])){
            echo $_POST['username'];
            //process the form
            //make the database query and check the password
            //if user does not confirm make the error variable 
            $error = "Username or Password not correct!";
        }
    ?>
    
    <!DOCTYPE html>
        <html>
            <head>
                <meta charset="UTF-8">
                <title>Form Proccessing</title>
            </head>
            <body>
                <?php if(isset($error)) { ?>
                <div class="error">
                    <?php echo $error; ?>
                </div>
                <?php } ?>  
                <form  method="post" action="">
                    Username: <input type="text" name="username"><br>
                    Password: <input type="password" name="password"><br>
                    <input type="submit" name="submit" value="Go!">
                </form>
            </body>
        </html>
    

    Other way is to make Ajax request to checkuser-pass.php

    Other way is to use two page form processing but to redirect from checkuser-pass.php back to the form page and use session variable for the errors.

    评论

报告相同问题?

悬赏问题

  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决