How to make a simple registration login page with jqueryajax+php

Source: Internet
Author: User
This article mainly describes how to make use of jqueryajax+php to create a simple registration login page, interested in the friend's reference, I hope to help you.

HTML structure


<p class= "Container" ><form>      <label> user name </label>    <input id= "username" type= "text "Name=" username "class=" Form-control "/>      <label> password </label>    <input id=" password "type=" Password "name=" password "class=" Form-control "/>      <button type=" button "id=" Login "class=" btn btn-primary " > Login </button>      <button type= "button" id= "sign" class= "BTN Btn-danger" > Registration </button>  </ form> <p id= "P" ></p></p>

Front desk JS


$ ("#login"). Click (function () {var senddata = {"username": $ ("#username"). Val (), "Password": $ ("#password"). Val ()}$. Ajax ({URL: "action/login.php", type: "POST", data:senddata,success:function (data) {if (data==1) {$ ("#p"). HTML ("password correct") }else if (data==2) {$ ("#p"). HTML ("password incorrect")}else if (data==3) {$ ("#p"). HTML ("account does not Exist")}})}) $ ("#sign"). Click (function () { var senddata = {"username": $ ("#username"). Val (), "Password": $ ("#password"). Val ()}$.ajax ({url: "action/adduser.php", Type: "POST", data:senddata,success:function (data) {if (data==1) {$ ("#p"). HTML ("User exists cannot register")}else if (data==2) {$ ("#p"). HTML ("Registration succeeded")}})})

Backstage login.php

$username = $_post[' username '); $password = $_post[' password '); $conn = Mysqli_connect ("localhost", "root", "", "Login") Or Die ("Connection Failed"); Mysqli_query ($conn, "Set names UTF8"); $result = Mysqli_query ($conn, "select * from user where username= ' $ Username ' "), if ($row =mysqli_fetch_array ($result)) {if ($row [" Password "]== $password) {echo 1;//password is correct}else{echo 2;// The password is incorrect}}else{echo 3;//account is incorrect}

Backstage adduser.php

$username = $_post[' username '); $password = $_post[' password '); $conn = Mysqli_connect ("localhost", "root", "", "Login") Or Die ("Connection Failed"); Mysqli_query ($conn, "Set names UTF8"); $result = Mysqli_query ($conn, "select * from user where username= ' $ Username ' "), if ($row =mysqli_fetch_array ($result)) {echo 1;//" user exists cannot register "}else{mysqli_query ($conn," insert INTO ' "User" ( ' username ', ' password ') VALUES (' $username ', ' $password ') "); Echo 2;//Registration Successful}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.