当前位置:网站首页>DAY6:利用 PHP 编写登陆页面
DAY6:利用 PHP 编写登陆页面
2022-07-29 05:18:00 【EdmunDJK】
DAY6:利用 PHP 编写登陆页面
这里代码直接放出了,太懒了,就不细致详解了
这里创建几个 php 文件
1、代码展示
图中蓝底的文件,这里放出其中的代码(login.php、signup.php、conn.php)
1.1、login.php
<?php
error_reporting(0);
session_start();
$postUsername =isset($_POST['username'])? $_POST['username'] : '';//用户名
$postpassword =isset($_POST['password'])? $_POST['password'] : '';//密码
$conn = mysqli_connect("127.0.0.1","root","admin123", "regist") or die("数据库连接出错!");//相应的数据库地址 用户名 和密码
$sql ="SELECT username,password1 FROM users WHERE username ='$postUsername'";
$query =mysqli_query($conn,$sql);
$row =mysqli_fetch_array($query,MYSQLI_ASSOC);
$username =isset($row['username'])? $row['username'] : '';
$password =isset($row['password1'])? $row['password1'] : '';
$_SESSION["username"]=$postUsername;
if(isset($_POST['login']))
{
if($username ==$postUsername && $password==$postpassword)
{
echo"<script>alert('登录成功');window.location ='1.php'</script>";
}
else
{
echo"<script>alert('用户名或密码错误!');history.go(-1)</script>";
}
}
$user;
?>
<!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>
</head>
<body>
<h2>登陆页面</h2>
<form action ="" method = "post" name ="myform" ousubmit ="return Checked();">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td><input type="submit" name="login" value="登录"></td>
<td><a href ="signup.php">注册</a></td>
</tr>
<tr>
<td><a href="7.html">返回首页</a></td>
</tr>
</table>
</form>
</body>
</html>
因为之前写的有些问题,调试时将 include() 函数注释了,所以这个文件并没有使用 include(conn.php);
1.2、signup.php:
<?php
session_start();
include("conn.php");//连接数据库
$username =isset($_POST['username'])? $_POST['username'] : '';//用户名
$password2 =isset($_POST['password2'])? $_POST['password2'] : '';//密码
$password1 =isset($_POST['password1'])? $_POST['password1'] : '';
if(isset($_POST['signup']))
{
if($password2==$password1)
{
$sql ="INSERT INTO users VALUE('$username','$password2');";
mysqli_query($conn,$sql);
echo "<script>alert('注册成功');window.location ='login.php';</script>";
}
else
{
echo "<script>alert('两次密码不一致!');window.location ='login.php';</script>";
}
}
?>
<!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>Document</title>
</head>
<body>
<h2>注册页面</h2>
<form action ="" method = "post" name ="myform" ousubmit ="return Checked();">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password1"></td>
</tr>
<tr>
<td>确认密码:</td>
<td><input type="password" name="password2"></td>
</tr>
<tr>
<td><input type="submit" name="signup" value="注册"></td>
<td><a href ="login.php">登录</a></td>
</tr>
<tr>
<td><a href="7.html">返回首页</a></td>
</tr>
</table>
</form>
</body>
</html>
1.3、conn.php
<?php
$conn = mysqli_connect("127.0.0.1","root","admin123") or die("数据库连接出错!");//相应的数据库地址 用户名 和密码
$selected = mysqli_select_db($conn,"regist");
?>
关键地方已经注释,一些重要函数可以在菜鸟教程中搜索
2、展示图
登陆界面
注册界面
返回首页
边栏推荐
- 利用Poi-tl在word模板表格单元格内一次插入多张图片和多行单元格相同数据自动合并的功能组件
- Wechat applet - component parameter transmission, state management
- Related knowledge of elastic box
- Liang Yuqi, founder of aitalk: the link between image and virtual reality
- href与src的区别
- End of document
- B - identify floating point constant problems
- Abstract classes and interfaces
- 弹性盒子flex
- 用threejs 技术做游戏跑酷
猜你喜欢
随机推荐
Qt设置背景图片方法
[typescript] learn typescript object types in depth
Using POI TL to insert multiple pictures and the same data of multiple rows of cells into the table cells of word template at one time, it is a functional component for automatic merging
About local variables
rem与px与em异同点
Camunda 1、Camunda工作流-介绍
[C language series] - three methods to simulate the implementation of strlen library functions
Niuke network programming problem - [wy22 Fibonacci series] and [replace spaces] detailed explanation
ClickHouse学习(八)物化视图
HCIA-R&S自用笔记(25)NAT技术背景、NAT类型及配置
Qt布局管理--部件拉伸(Stretch)原理及大小策略(sizePolicy)
Solve the problem that the prompt information of form verification does not disappear and the assignment does not take effect
Database operation day 6
微信小程序更改属性值-setData-双向绑定-model
Detailed installation and use tutorial of MySQL (nanny installation with pictures and texts)
href与src的区别
ClickHouse学习(六)语法优化
Clickhouse learning (VI) grammar optimization
小程序中的DOM对象元素块动态排序
ClickHouse学习(十一)clickhouseAPI操作