用户名/密码错误,并重定向 [英] Incorrect username / password message and redirect

查看:106
本文介绍了用户名/密码错误,并重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建客户登录区域.我在clientLogin.html中有登录表单:

Creating a Client Login area. I have my log in form in a clientLogin.html:

       <form name="ClientLogin" method="post" action="login.php"> <br>
            <p>
             <label for='Username'>Username</label> <br>
            <input type="text" name="username" />
            </p>
            <p>

            <label for='Password'>Password</label> <br>
            <input type="password" name="password" />
            </p>
            <br>
            <input type="submit" value="Submit" />

        </form>

如果用户名&密码组合不正确我想重定向到此页面,并添加一条消息:用户名/密码不正确,请重试".这是login.php中的代码:

If the username & password combination are incorrect I want to redirect to this page adding a message saying "incorrect username/ password please try again". This is the code from login.php:

<?php


//Connect to the database
    require('db.php');

    $user = mysql_real_escape_string($_POST["username"]);
    $pass = mysql_real_escape_string($_POST["password"]);

    $clientdata = mysql_query("SELECT * FROM Users WHERE username='$user' and            password='$pass'")
    or die (mysql_error());

    $data = mysql_fetch_array($clientdata, MYSQL_ASSOC);

    if(mysql_num_rows($clientdata) == 1){

session_start();


$_SESSION['username'] = $user;


header('Location: profile.php');

    }else{
header('Location: clientLogin.html');
    }

我希望clientLogin.html文件需要更改为.php文件.除此之外,我很沮丧.任何指导将不胜感激.

I expect the clientLogin.html files needs changing to a .php file. other than that I am stumped. Any guidance would be greatly appreciated.

推荐答案

您需要将clientLogin.html的扩展名从.html更改为.php

You need to change extension of clientLogin.html from .html to .php

header('Location: clientLogin.html');更改为header('Location: clientLogin.php');

将这部分代码添加到clientLogin.php页面顶部:

Add this part of code at the top of your clientLogin.php page:

<?php 
session_start();
if(empty($_SESSION['username'])) {
 echo 'incorrect username/ password please try again.' ;
}
?> 

这篇关于用户名/密码错误,并重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆