Back end interaction

Keywords: PHP Database SQL JSON

First step

(1) Form login settings and form validation

  1> Set click event - > get the password value of the account entered in the form - > use regular expression to verify the form - > send ajax request - > enter the background - > Import configuration file - > receive the data sent by ajax - > connect to the database - > write sql statement - > query the database - > judge the query result - > assume the query succeeds - > open session ﹐ start() -- store the background Data - > set the response type (in json format) - > output data - > the browser can judge whether the request is successful by obtaining the data stored in the background -- > if the request is successful, jump to the page -- > jump to the page again to verify whether the login is successful.

      //Verify the form on the browser side first
        //Click event of login button registration
          //1. Collect the password of the user's mailbox
          var email=$("#email").val();
          var password=$("#password").val();
          //2. Data validation / / form validation on browser side
          var reg=/\w+\@\w+\.\w+/;
            $("#msg").text(" there is an error in the information you entered, please re-enter ");
          //Form password length
          var pwdReg=/\w{3,20}/;
            $("#msg").text('wrong password length, please re-enter ');
            email : email,
            password : password},
                alert('Login successfully');
              // If the connection successfully jumps to the background page
                $("#msg").text('wrong user name or password ');
    require_once '../../config.php';
    require_once '../../functions.php';
    // Backstage
    // Receive email and password from ajax
    // Query whether the database has this mailbox and password
    //  Connect to database
    $sql="select * from users where email='{$email}' and 
    password='{$password}' and status='activated'";
    // Implementation of sql
    $queryResult=query($connect,$sql);  //Two dimensional array has a found user
    $response=["code"=>0,"msg"=>"operation failed"]; // If no one returns to failure
    // If there's evidence of this person, the login is successful
    if($queryResult){//Login successfully
        //Login successful remember he's logged in
        session_start();//Be sure to turn it on first
        $_SESSION['isLogin']=1;//The value of isLogin is 1 for login
        // Remember that the id of the currently logged in person will be used later
        $response["msg"]="Login successfully";
    // Return in json format     
    echo json_encode( $response );



Posted by debigmac on Sun, 09 Feb 2020 12:00:16 -0800