开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第1天,点击查看活动详情
1.注册页面:
<!DOCTYPE html>
<html lang="en"><head><meta http-equiv="Content-Type" content="charset=UTF-8">
<title>注册</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<div id="loginDiv">
<form action="" method="POST">
<h1 style="text-align: center;color: aliceblue;">注册</h1>
<p>username:<input type="text" name="username" id='mz'>
<label name="username"></label>
</p>
<p>password:<input type="password" name="password" id='ps'>
<label name="password" ></label>
</p>
<p>Confirm password:<input type="password" name="password" id='ps3'>
<label name="password" ></label>
</p>
<div style="text-align: center;margin-top: 30px;">
<input type="reset" class="button" id='btn' value="确认注册" style="text-align: center;">
<a href="JQ1.html" target="_blank"><input type="button" value="前往登录" class="button"></a>
</div>
</form>
</div>
</body>
<ml>
2.登录页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="charset=UTF-8">
<title>登录</title>
</head>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<body>
<div id="loginDiv">
<form action="" method="POST">
<h1 style="text-align: center;color: aliceblue;">登录</h1>
<p>username:<input type="text" id='mz'><!-- mz输入框 -->
<label name="username"></label>
</p>
<p>password: <input type="password" id='ps' name="password"><!-- ps输入框 -->
<label name="password"></label>
</p>
<p>Confirm password:<input type="password" name="password" id='ps3'>
<label name="password" ></label>
</p>
<div style="text-align: center;margin-top: 30px;"><!-- 该div是下面两个按钮的布局块 -->
<input type="submit" class="button" value=" 确认登录"id="btn"><!-- 该按钮的id是btn,所以点击该按钮触发的就是上面的js-->
<a href="JQ2.html" target="_blank"><input type="button" value="前往注册" class="button" style="text-align: center;"></a>
</div>
</form>
</div>
</body>
<ml>
登录对应的php:
<?php
$con=mysqli_connect("127.0.0.1","","","jq");//第个root为数据库名,第二个为数据库的密码,最后为新建的数据库表
$program_char="utf8";
mysqli_set_charset($con,$program_char);
if (!$con) {
die("连接失败: " . mysqli_connect_error());
}
$re1=mysqli_query($con,$sql1);
$row1=mysqli_num_rows($re1);
$re2=mysqli_query($con,$sql2);
$row2=mysqli_num_rows($re2);
if($row1){
echo "登录成功";
exit;
}
else if($row2){
echo "密码错误";
exit;
}
else{
echo "用户不存在";
}
mysqli_close($con)
?>
下面简述一下连接数据的步骤: 1.首先确保下图app打开
如果出现下图样式证明已经打开
2.打开数据库
然后建一个如下的数据库表 (可以任意建表但是必须保证起的表名必须和上面php里面的代码对应,否则会报错)
在登录页面中:
对应的php核心代码:
前端获取了输入的用户名和密码值,然后传到下面的后端中,之后将传到后端的值传到数据库表中
其中访问页面要使用如下路径: (其实127.0.0.1和localhost是一样的效果,他们后面放的路径就是WWW下的路径)
下面进行测试阶段:
如果登录输入两次密码不一致时会弹出如下的窗口
如果登录输入的密码和注册时不同则会弹出如下的窗口:
如果登录输入为空格或为空时会弹出如下的页面:
上述只是进行测试,提供大概的思路哦!
如果需要完整的登录注册系统可以私信我呀.