form表單簡易註冊登錄

註冊頁面:php

htmlhtml

<form action="updata.php" method="post" id="text_form">

<div class="yuanGongH ipt">員工號:<input type="text" id="ygh" value="" name="ygh"></div> <div class="phone ipt"><i>手機號:<input type="text" value="" name="phone" id="phone"></div> <div class="szmm ipt">密碼:<input type="text" value="" name="password" id="pass"></div> <div class="qrmm ipt">確認密碼:</i><input type="text" value="" name="qrpass" id="qrpass"></div> </form> <div class="btn_zhuce">註冊</div>

jsmysql

 $(".btn_zhuce").click(function(){

            var text_form = document.getElementById('text_form');
            var ygh = document.getElementById("ygh").value;
            var phone = document.getElementById("phone").value;
            var pass = document.getElementById("pass").value;
             var qrpass = document.getElementById("qrpass").value;
                    if(ygh == "" ){
                            alert("員工號不能爲空");
                            return false;
                            }
                if(phone == "" ){
                            alert("電話不能爲空");
                            return false;
                            }

                if(pass == "" ){
                            alert("密碼不能爲空");
                            return false;
                            }
                if(qrpass !== pass){
                            alert("密碼不一樣");
                            return false;
                            }

                else{
                            text_form.submit();
                            
                            return true;
                            }

        })

phpsql

<?php 

$ygh=$_POST['ygh'];
$phone=$_POST['phone'];
$pass=$_POST['password'];
$qrpass=$_POST['qrpass'];

$servername = "localhost";
$username = "root";
$password = "123456";
$dbname = "bsbeijing";

// 建立鏈接   面向過程寫法
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("鏈接失敗: " . mysqli_connect_error());
}
mysqli_query($conn,'set names utf8');//設置字符集

$sql = "INSERT INTO zhuce(`ygh`, `phone`,`password`,`qrpass`)  VALUES ('$ygh', '$phone','$pass','$qrpass')";//查詢這個表

//判斷是否成功
if (mysqli_query($conn, $sql)) {
    echo "<script>window.location.href='denglu.html';alert('註冊成功')</script>";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);

 ?>

登陸頁:post

htmlspa

<form action="downdata.php" method="post" id="text_form">

<div class="yuanGongH ipt"><i><img src="images/icon1_03.png" alt=""></i><input type="text" value="" id="ygh" name="ygh"></div> <div class="miM ipt"><i><img src="images/icon2_03.png" alt=""></i><input type="text" name="pass" id="pass" value="" ></div>

</form> <div class="zcwj"><span><a href="zhuce.html">註冊</a></span></div> <div class="btn_denglu">登錄</div>

jscode

$(".btn_denglu").click(function(){

            var text_form = document.getElementById('text_form');
            var ygh = document.getElementById("ygh").value;
            var pass = document.getElementById("pass").value;
             
            text_form.submit();
                            
            return true;
                          
        })

phporm

<?php

$ygh=$_POST["ygh"];
$pass=$_POST["pass"];

$servername = "localhost";
$username = "root";
$password = "123456";
$dbname = "bsbeijing";

// 建立鏈接   面向過程寫法
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("鏈接失敗: " . mysqli_connect_error());
}
mysqli_query($conn,'set names utf8');//設置字符集
$sql = "SELECT ygh, password FROM zhuce WHERE (ygh='$ygh') AND (password='$pass')";//查詢這個表特定值
$result = mysqli_query($conn, $sql);//結果
if ($result->num_rows > 0) {
  
echo "<script>window.location.href='tjdh.html';</script>";
 } else {
  echo "<script>window.location.href='denglu.html';alert('帳號密碼錯誤')</script>";
 }
 
 
mysqli_close($conn);
?>
相關文章
相關標籤/搜索