亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP login registration login

As we mentioned in the previous course, click the login button and the form is submitted to main.php

Let’s take a look at the specific content of the following main.php file

First we put The file to connect to the database is introduced, that is, the conn.php file

require_once("conn.php"); //Introduce the file to connect to the database

Form submission The way is to submit it by post

So we need to get the content of the form

$name=$_POST['username'];

$password=$_POST[ 'password'];

The two variables are used to store the values ??received in the post method

Let's first look at the login flow chart:

login.png

Next we have to think about login, under what circumstances the login is successful

When the information submitted by our form exists in the database table, then we can log in. If there is no such user, then Can't log in

So we write the query statement

$sql = "select * from user where username='$name' and password='$password'";

Then execute the sql statement

$info = mysql_query($sql);

In this way, we have queried the result. Through the mysql_fetch_row function, we obtain a row from the result set as a numeric array

$row = mysql_fetch_row($info);

Then we have to judge $row. If it is queried, the login is successful, otherwise it is a failure;

The complete code is as follows:

<?php
    require_once("conn.php");//首先鏈接數(shù)據(jù)庫

    $name=$_POST['username'];
    $password=$_POST['password'];

    $sql = "select * from user where username='$name' and password='$password'";
    $info = mysql_query($sql);
    $row = mysql_fetch_row($info);
    if($row){
        echo "<script>alert('登錄成功')</script>";
    }else{
        echo "<script>alert('登錄失敗')</script>";
        //echo "<script>history.go(-1);</script>";   //登錄失敗返回上一個(gè)頁面
        echo "<script>location.href='login.php';</script>";  //登錄失敗,跳轉(zhuǎn)到另外一個(gè)頁面
    }

?>
Continuing Learning
||
<?php require_once("conn.php");//首先鏈接數(shù)據(jù)庫 $name=$_POST['username']; $password=$_POST['password']; $sql = "select * from user where username='$name' and password='$password'"; $info = mysql_query($sql); $row = mysql_fetch_row($info); if($row){ echo "<script>alert('登錄成功')</script>"; }else{ echo "<script>alert('登錄失敗')</script>"; //echo "<script>history.go(-1);</script>"; //登錄失敗返回上一個(gè)頁面 echo "<script>location.href='login.php';</script>"; //登錄失敗,跳轉(zhuǎn)到另外一個(gè)頁面 } ?>
submitReset Code