国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

前端注冊登錄頁面數(shù)據(jù)庫交互(h5+css+php+mysql+axios)

這篇具有很好參考價值的文章主要介紹了前端注冊登錄頁面數(shù)據(jù)庫交互(h5+css+php+mysql+axios)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一個登錄注冊界面,并使用前端數(shù)據(jù)庫實現(xiàn)登陸注冊功能?

首先是index.html

直接在index.html里面寫了用axios,實現(xiàn)注冊和登錄

效果圖

前端注冊登錄頁面數(shù)據(jù)庫交互(h5+css+php+mysql+axios)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登錄/注冊</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container">
        <div class="container-forms">
            <div class="container-info">
                <div class="info-item">
                    <div class="table">
                        <div class="table-cell">
                            <p>
                                若有賬號,點擊登錄
                            </p>
                            <button class="info-btn">
                                登 錄
                            </button>
                        </div>
                    </div>
                </div>
                <div class="info-item">
                    <div class="table">
                        <div class="table-cell">
                            <p>
                                沒有賬號,沒有注冊
                            </p>
                            <button class="info-btn">
                                注 冊
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="container-form">
                <div class="form-item log-in">
                    <div class="table">
                        <div class="table-cell">
                        <div>
                           
                            <input id="username" name="username" placeholder="用戶名" required>
                          </div>
                          <div>
                              
                              <input type="password" id="password" name="password" placeholder="密碼" required name="password">
                            </div>
                            <div>
                              <button class="btn" type="button" id="btn1">登 錄</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-item sign-up">
                    <div class="table">
                        <div class="table-cell">
                           <div>           
                            <input id="username1" name="username1" placeholder="用戶名" required>
                          </div>
                          <div>                           
                              <input type="password" id="password1" name="password1" placeholder="密碼" required name="password1">
                            </div>
                            <div>                           
                                <input type="password" id="password2" name="password2" placeholder="確認密碼" required name="password2">
                              </div>
                            <div>
                              <button class="btn" type="button" id="btn2"> 注 冊</button>
                            </div>
                            
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="script.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        //獲取元素
        var btn1 = document.getElementById("btn1");
        var usernameInput = document.getElementById("username");
        var passwordInput = document.getElementById("password");
    
        //添加點擊事件
        btn1.onclick = function(){
            //獲取用戶輸入的用戶名和密碼
            var username = usernameInput.value;
            var password = passwordInput.value;
    
            //發(fā)送ajax到登錄接口
            $.post("./php/login.php",{username:username,password:password},function(data){
                alert(data.data);
                if (data.error == 0){
                   // 登錄成功
                   location.href = 'success.html'
                }
            },"json")
        }
    </script>


    <script>//注冊
        //獲取元素
        var btn2 = document.getElementById("btn2");
        var username1Input = document.getElementById("username1");
        var password1Input = document.getElementById("password1");
        var password2Input = document.getElementById("password2");
        
        //添加點擊事件
        btn2.onclick = function(){
            //獲取用戶輸入的用戶名和密碼
            var newusername = username1Input.value;
            var newpassword1 = password1Input.value;
            var newpassword2 = password2Input.value;
            if (newpassword1!=newpassword2)
            {
            alert("兩次密碼不一致,請重新輸入");
            }
            else{
            //發(fā)送ajax到登錄接口
            $.post("./php/register.php",{username:newusername,password:newpassword1,pwd:newpassword2},function(data){
                alert(data.data);
                if (data.error == 0){
                   // 成功
                   location.href = './index.html'
                }
            },"json")
        }
        }
    </script>
</body>
</html>

登錄注冊滑動實現(xiàn)

script.js

const info_btn = document.getElementsByClassName("info-btn")
for (let i = 0; i < info_btn.length; i++) {
  info_btn[i].onclick = () => {
    document.querySelector(".container").classList.toggle("log-in");
  }; 
}

style.css


body{
    /* 絕對定位    */
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    font-family: "Roboto",sans-serif;
    background-color: #fff4e6;
    /* 溢出隱藏 */
    overflow: hidden;
}

.table{
    display: table;
    width: 100%;
    height: 100%;
}

.table-cell{
    display: table-cell;
    vertical-align: middle;
    transition: all 0.5s;
}

.container{
    /* 相對定位 */
    position: relative;
    width: 600px;
    margin: 30px auto 0;
    height: 320px;
    background-color: #854442;
    top: 50%;
    margin-top: -160px;
    transition: all 0.5s;
}

.btn , .info-btn{
    display: block;
    border: none;
    text-align: center;
    margin: 0 auto;
    color: #fff;
    background-color: #be9b7b;
}
.info-btn{
    padding: 5px 10px;
}

.btn:hover{
    opacity: 0.7;
}
.btn ,input{
    padding: 10px 15px;
}

input{
    margin: 0 auto 15px;
    display: block;
    width: 220px;
}

.container-info{
    font-size: 0;
}

.info-item{
    text-align: center;
    width: 300px;
    height: 320px;
    display: inline-block;
    color: #fff;
}

.info-item p{
    font-size: 20px;
    margin: 20px;
}

.info-item .btn1{
    background-color: transparent;
    border: 1px solid #fff;
}

.info-item .table-cell{
    padding-right: 35px;
}
.info-item:nth-child(2) .table-cell{
    padding-left: 35px;
    padding-right: 0;
}

.container-form{
    /* 溢出隱藏 */
    overflow: hidden;
    position: absolute;
    left: 30px;
    top: -30px;
    width: 305px;
    height: 380px;
    background-color: #fff;
    box-shadow: 0 0 15px 0 rgba(0, 0, 0, 0.2);
    transition: all 0.5s;
}

.container-form .btn1{
    margin-top: 30px;
}

.form-item{
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    opacity: 1;
    transition: all 0.5s;
}

.form-item.sign-up{
    position: absolute;
    left: -100%;
    opacity: 0;
}
.container.log-in .container-form{
    left: 265px;
}


.container.log-in .container-form .form-item.sign-up{
    left: 0;
    opacity: 1;
}

.container.log-in .container-form .form-item.log-in{
    top: -100%;
    opacity: 1;
}

然后是登錄和注冊的php

login.php

<?php
    //接收前端傳遞過來的數(shù)據(jù)
    $username = $_POST["username"];
    $password = $_POST["password"];

    //連接數(shù)據(jù)庫
    $conn = mysqli_connect("localhost","root","123456","login");

    //定義查詢語句
    $selectSQL = "SELECT * FROM register WHERE username='$username' and password='$password'";
    //是否查詢到
    $result = mysqli_query($conn , $selectSQL);

    //獲取結果集中的數(shù)據(jù)條數(shù)
    $num = mysqli_num_rows($result);

    //echo $num;
    //根據(jù)條數(shù)做判斷
    if ($num ==1 ){
        //查到了數(shù)據(jù) 允許登錄
        echo json_encode(array("error" =>0,"data" =>"登錄成功"));
    }
    else{
        //不允許登錄
        echo json_encode(array("error" =>1,"data" =>"登錄失敗"));
    }
?>

register.php文章來源地址http://www.zghlxwxcb.cn/news/detail-504677.html

<?php
    //接收前端傳遞過來的數(shù)據(jù)
    $username = $_POST["username"];
    $password = $_POST["password"];
    $pwd = $_POST["pwd"];

    //連接數(shù)據(jù)庫
    $conn = mysqli_connect("localhost","root","123456","login");

    //定義查詢語句
    $selectSQL = "SELECT * FROM register WHERE username='$username'";
    //是否查詢到
    $result = mysqli_query($conn , $selectSQL);

    //獲取結果集中的數(shù)據(jù)條數(shù)
    $num = mysqli_num_rows($result);

    //echo $num;
    //根據(jù)條數(shù)做判斷
    if ($num ==1 ){
        //查到了數(shù)據(jù) 允許登錄
        echo json_encode(array("data" =>"已存在賬號"));
        exit;
    }
    else{
        
    //定義添加語句
    $insertSQL = "INSERT INTO register (username,password,pwd) VALUES ('$username','$password','$pwd')";  
 
    //是否添加到
    $result1 = mysqli_query($conn , $insertSQL);
   
    if ($result1){
        //注冊成功
        echo json_encode(array("error" =>0,"data" =>"注冊成功"));
    }
    else{
        //注冊失敗
        echo json_encode(array("error" =>1,"data" =>"注冊失敗"));
    }
    }
?>

到了這里,關于前端注冊登錄頁面數(shù)據(jù)庫交互(h5+css+php+mysql+axios)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內(nèi)容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • 使用javaweb實現(xiàn)登錄注冊頁面,并且對功能和業(yè)務進行分層 用戶登錄成功跳轉到主頁并展示數(shù)據(jù)庫的商品的信息

    使用javaweb實現(xiàn)登錄注冊頁面,并且對功能和業(yè)務進行分層 用戶登錄成功跳轉到主頁并展示數(shù)據(jù)庫的商品的信息

    一、Servlet+JSP+JavaBean開發(fā)模式(MVC)介紹 Servlet+JSP+JavaBean模式(MVC)適合開發(fā)復雜的web應用,在這種模式下,servlet負責處理用戶請求,jsp負責數(shù)據(jù)顯示,javabean負責封裝數(shù)據(jù)。 Servlet+JSP+JavaBean模式程序各個模塊之間層次清晰,web開發(fā)推薦采用此種模式。 這里以一個最常用的用戶登錄

    2024年02月03日
    瀏覽(109)
  • web開發(fā)中,簡單的案例說明前端頁面和后端以及mysql數(shù)據(jù)庫的交互過程

    web開發(fā)中,簡單的案例說明前端頁面和后端以及mysql數(shù)據(jù)庫的交互過程

    ????????首先這是一個基于 web開發(fā) 的稿子,作者也是轉java20天左右,以前也一直迷惑起那段頁面是如何和后端進行交互,數(shù)據(jù)提交提交到了哪里?后端開發(fā)如何獲取到前端提交的數(shù)據(jù)呢?后端數(shù)據(jù)提交到數(shù)據(jù)庫中應該如何處理,接下來通過一個簡單的例子,登錄案例 (實

    2024年02月03日
    瀏覽(23)
  • Node.js連接數(shù)據(jù)庫 實現(xiàn)注冊、登錄、判斷注冊

    Node.js連接數(shù)據(jù)庫 實現(xiàn)注冊、登錄、判斷注冊

    Node.js連接數(shù)據(jù)庫實現(xiàn)注冊,登錄,在登錄時檢測賬號是否進行注冊。 此創(chuàng)建文件夾可以不是使用Vue-cli進行創(chuàng)建,只是簡單創(chuàng)建文件夾便可。 使用npm進行mysql插件的安裝,cmd黑窗口運行下列指令 此指令運行完成,文件夾根目錄出現(xiàn) node_modules 文件 黑窗口運行 npm init 指令,出現(xiàn)

    2024年02月09日
    瀏覽(41)
  • Qt 數(shù)據(jù)庫的注冊和登錄功能

    Qt 數(shù)據(jù)庫的注冊和登錄功能

    widget.h widget.cpp ?client.h client.cpp ?main函數(shù) 窗口設計部分 最終效果圖:

    2024年02月07日
    瀏覽(22)
  • Flutter框架實現(xiàn)登錄注冊功能,不連接數(shù)據(jù)庫

    要在Flutter框架中實現(xiàn)登錄和注冊功能,而不連接數(shù)據(jù)庫,可以使用本地存儲來存儲用戶信息。以下是一個簡單的示例,演示如何使用本地存儲來實現(xiàn)登錄和注冊功能。 首先,我們需要添加 shared_preferences 插件到 pubspec.yaml 文件中: 然后,在 lib 文件夾中創(chuàng)建一個新的文件夾

    2024年02月08日
    瀏覽(25)
  • MVC框架實現(xiàn)用戶登錄注冊功能(連接數(shù)據(jù)庫)

    MVC框架實現(xiàn)用戶登錄注冊功能(連接數(shù)據(jù)庫)

    一、簡單理解MVC框架 二、項目結構 三、項目源碼 3.1 User 3.2?UserDao 3.3?RegisterDao 3.4?servletControll 3.5 servletControllRegister 3.6?web.xml 3.7?login.jsp 3.8?register.jsp 3.9?success.jsp 3.10?failure.jsp ?四、實現(xiàn)效果 總結 本篇文章主要介紹利用MVC框架去實現(xiàn)一個簡單的用戶登錄注冊功能,內(nèi)容主

    2024年02月06日
    瀏覽(38)
  • JavaWeb實現(xiàn)簡易的注冊登錄功能(與數(shù)據(jù)庫連接)

    JavaWeb實現(xiàn)簡易的注冊登錄功能(與數(shù)據(jù)庫連接)

    一、創(chuàng)建數(shù)據(jù)庫表連接 這里我們創(chuàng)建一個數(shù)據(jù)庫名為db_user,創(chuàng)建庫的使用可視化工具很簡單就不細說了,下面sql代碼塊是我們創(chuàng)建一個簡易用戶表為了方便我們后續(xù)進行登錄注冊操作。 下面就是建好的表: 1、建一個與數(shù)據(jù)庫連接的file文件:db.properties 二、創(chuàng)建前端頁面 1、

    2024年01月19日
    瀏覽(23)
  • java連接數(shù)據(jù)庫實現(xiàn)登錄與注冊小功能(小白版)

    java連接數(shù)據(jù)庫實現(xiàn)登錄與注冊小功能(小白版)

    準備工作: 創(chuàng)建數(shù)據(jù)庫stu;? ? ? ? create database stu charset=utf8; 使用數(shù)據(jù)庫stu;? ? ? ? ? ? use stu; 創(chuàng)建用戶表user(id,username,password,nick) create table user(id int primary key auto_increment,username varchar(50),password varchar(50),nick varchar(50)); ? 1.開始創(chuàng)建springboot工程,勾選Web-spring Web,? SQL-MyBatis Frame

    2024年02月08日
    瀏覽(18)
  • Java--用戶登錄/注冊界面(連接Mysql數(shù)據(jù)庫)并可以通過驗證碼登錄

    Java--用戶登錄/注冊界面(連接Mysql數(shù)據(jù)庫)并可以通過驗證碼登錄

    1 效果展示 (1)登錄界面 (2)注冊界面 (3)動圖展示 2 內(nèi)容說明 (1)開發(fā)前,需引入一個連接Mysql 數(shù)據(jù)庫驅(qū)動mysql-connector-java-5.1.30-bin.jar包 提取碼:6666 (2)構建路徑 (3)需要下載xampp軟件 xampp軟件下載 提取碼:2255 xampp軟件包含 Apache Web服務器、 Mysql Web服務器、Filezilla

    2024年02月09日
    瀏覽(95)
  • (代碼注釋超詳細)JavaWeb連接Mysql數(shù)據(jù)庫完成登錄注冊業(yè)務

    (代碼注釋超詳細)JavaWeb連接Mysql數(shù)據(jù)庫完成登錄注冊業(yè)務

    登錄:完成連接數(shù)據(jù)庫判斷登陸信息是否有誤 注冊:將信息填寫完畢后點擊注冊,跳轉到登陸頁面 主頁:展示項目信息并且可以在頁面內(nèi)進行增刪改操作 完整文件目錄如下: 文件目錄: bean包中填寫的代碼為實體類 dao模型就是寫一個類,把訪問數(shù)據(jù)庫的代碼封裝起來 serv

    2023年04月22日
    瀏覽(21)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包