Website background login (2) Login processing

After finishing the previous section, how to write the backend login page of the website? In this section, we will talk about the login processing. Next, let’s take a look at how to determine whether the login is successful.

login.php The code is as follows:

<?php 
session_start (); 
require_once("../config/config.php");
    $password = $_POST['password'];
    //查询数据库 然后取出数据库的信息,如果和表单提交的信息一致,则登录成功,进入后台管理
    $sql = "select * from admin where  password='$password'";
    $res = mysql_query($sql);
    $row = mysql_fetch_row($res);
    if($row){
        echo "<script>alert('登录成功')</script>";
        echo "<script>location.href='index.php'</script>";
    }else{
        echo "<script>alert('登录失败')</script>";
        echo "<script>history.go(-1);</script>"; //登录失败返回上一个页面
    }
 ?>

Link to the database, and then use the sql statement to The information submitted by the form is judged against the information in the database. If the same user name and password can be found in the database, then the user can log in

If the login is successful, we jump to the background management page

Login failed, jump to the login page

Successful login is shown as follows:

微信截图_20170712094702.png

微信截图_20170712094813.png

Continuing Learning
||
<?php session_start (); require_once("../config/config.php"); $password = $_POST['password']; //查询数据库 然后取出数据库的信息,如果和表单提交的信息一致,则登录成功,进入后台管理 $sql = "select * from admin where password='$password'"; $res = mysql_query($sql); $row = mysql_fetch_row($res); if($row){ echo "<script>alert('登录成功')</script>"; echo "<script>location.href='index.php'</script>"; }else{ echo "<script>alert('登录失败')</script>"; echo "<script>history.go(-1);</script>"; //登录失败返回上一个页面 } ?>
submitReset Code