form表单简易注册登陆
注册页面:
html
<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>
js
$(".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; } })
php
<?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); ?>
登录页:
html
<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>
js
$(".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; })
php
<?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); ?>