用HTML表单登录PHP表单 [英] PHP Login form with HTML form

查看:99
本文介绍了用HTML表单登录PHP表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个登录表单。这是我的HTML表单代码

 < html> 
< head>
< title>登入< / title>
< link rel =stylesheettype =text / csshref =style.css/>
< / head>
< body>
< div class =container login>
< h2 class =form-signin-heading>用户登录< / h2>
< input type =textname =usernamesize =20placeholder =Username>
< input type =passwordname =passwordsize =20placeholder =Password>< / br>
< input type =submitvalue =Log Inclass =btn btn-large btn-primary>
< a href =signup.html>注册< / a>
< / form>
< / div>
< / body>
< / html>
<?php
}
?>

这是我的PHP代码



<$ p $($ _ POST)&&!empty($ _ POST)){
session_start(); $ p $ <?php
if(isset
//连接数据库
include(config.php);

//在$ username变量中存储用户名。
$ username = mysql_real_escape_string(stripslashes($ _ POST ['username']));

//在$ password变量中存储密码。
$ password = mysql_real_escape_string(stripslashes(md5($ _ POST ['password'])));


$ match =SELECT id FROM $ table WHERE username ='。 $用户名。 '和密码'。 $密码。 ;;

$ qry = mysql_query($ match);

$ num_rows = mysql_num_rows($ qry);

if($ num_rows< = 0){

echo对不起,没有用户名$ username和指定的密码。

回声再试一次;

出口;

} else {

$ _SESSION ['user'] = $ _POST [username];
header(location:index.html); //页面在登录后重定向用户。
}
} // else {}
?>

我在数据库中插入了'mark99'用户名和'1234'密码,但它不断给我一个错误说:用户名不存在。任何想法?

解决方案

你说你已经在表格中插入 1234 作为密码了吗?





  $ password = mysql_real_escape_string(stripslashes(md5($ _ POST ['密码']))); 

您密码的含义意味着它不会再是$ password变量中的1234,这就是为什么它给出错误。



或者移除 md5()或在表格中插入1234的md5值


Im trying to create a login form. THis is my HTML form code

<html> 
<head>
<title>Login</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div class="container login">
<form action="login.php" method="post" class="form-signin" id = "login_form" >
<h2 class="form-signin-heading">User Login</h2>
<input type="text" name="username" size="20" placeholder="Username">
<input type="password" name="password" size="20" placeholder="Password"></br>
<input type="submit" value="Log In" class="btn btn-large btn-primary">
<a href="signup.html">Sign Up</a>        
</form>
</div>
</body>
</html>
<?php
}
?>

and this is my php code

<?php
    if (isset($_POST) && !empty($_POST)) {
        session_start();
        //connecting to the database
        include("config.php");

        //Storing username in $username variable.
        $username = mysql_real_escape_string(stripslashes($_POST['username']));

        //Storing password in $password variable.
        $password = mysql_real_escape_string(stripslashes(md5($_POST['password'])));


        $match = "SELECT id FROM $table WHERE username = '" . $username . "' and password'" . $password . "';";

        $qry = mysql_query($match);

        $num_rows = mysql_num_rows($qry);

        if ($num_rows <= 0) {

            echo "Sorry, there is no username $username with the specified password.";

            echo "Try again";

            exit;

        } else {

            $_SESSION['user'] = $_POST["username"];
            header("location:index.html"); // Page to redirect user after login.
        }
    } //else{}
?>

Ive inserted 'mark99' username and '1234' password into thedatabase however it keeps giving my an error saying the username doesn't exists. Any ideas?

解决方案

you said you have inserted 1234 as password in table right??

and in

$password = mysql_real_escape_string(stripslashes(md5($_POST['password']))); 

you are hasing the password mean it will not be 1234 any more in $password variable that's why its giving error.

either remove the md5() or insert the md5 value of 1234 in table

这篇关于用HTML表单登录PHP表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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