PHP实现简单注册登录 详细全部代码
码农天地 -PHP实现简单注册登录 详细全部代码 先看演示~
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/7773706580...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
https://xueqiu.com/2739090642...
示例图:
Ps.本人有点懒哈~ 就输出个成功算了吧~
代码里面注释写很详细了哦~ 废话不多说 直接上代码~
index.php代码:
`<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Zhe - 注册登录</title>
<link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui/css/layui.css" />
<script src="https://www.layuicdn.com/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<fieldset >
<legend>Zhe - 登录注册演示</legend>
</fieldset>
<div >
<div >
<div >
<div >
<div >注册</div>
<div >
<form action="register.php" method="post" onsubmit="return checkForm(this)" lay-filter="example">
<div >
<label >输入框</label>
<div >
<input type="text" name="username" placeholder="请输入账号" >
</div>
</div>
<div >
<label >密码框</label>
<div >
<input type="password" name="password" placeholder="请输入密码" >
</div>
</div>
<div >
<div >
<input type="submit" value="立即注册"/>
</div>
</div>
</form>
</div>
</div>
</div>
<div >
<div >
<div >登录</div>
<div >
<form action="login.php" method="post" onsubmit="return checkForm(this)" lay-filter="example">
<div >
<label >输入框</label>
<div >
<input type="text" name="username" placeholder="请输入账号" >
</div>
</div>
<div >
<label >密码框</label>
<div >
<input type="password" name="password" placeholder="请输入密码" >
</div>
</div>
<div >
<div >
<input type="submit" value="立即登录"/>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
// 验证输入不为空的脚本代码
function checkForm(form) {
if(form.username.value == "") {
alert("用户名不能为空!");
form.username.focus();
return false;
}
if(form.password.value == "") {
alert("密码不能为空!");
form.password.focus();
return false;
}
return true;
}
</script>
</body>
</html>`
* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
* 10
* 11
* 12
* 13
* 14
* 15
* 16
* 17
* 18
* 19
* 20
* 21
* 22
* 23
* 24
* 25
* 26
* 27
* 28
* 29
* 30
* 31
* 32
* 33
* 34
* 35
* 36
* 37
* 38
* 39
* 40
* 41
* 42
* 43
* 44
* 45
* 46
* 47
* 48
* 49
* 50
* 51
* 52
* 53
* 54
* 55
* 56
* 57
* 58
* 59
* 60
* 61
* 62
* 63
* 64
* 65
* 66
* 67
* 68
* 69
* 70
* 71
* 72
* 73
* 74
* 75
* 76
* 77
* 78
* 79
* 80
* 81
* 82
* 83
* 84
* 85
* 86
* 87
login.php代码:
`<?php
session_start();
header("content-type:text/html;charset=utf-8");
//连接数据库
$link = mysqli_connect("localhost","pay_com_cn","pay_com_cn","pay_com_cn");
if (!$link) {
die("连接失败: " . mysqli_connect_error());
}
//接收$_POST用户名和密码
$username = $_POST['username'];
$password = $_POST['password'];
//查看表user用户名与密码和传输值是否相等
$sql = "SELECT * FROM user WHERE username = '$username' AND password = '$password'";
//result必需规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。
$result = mysqli_query($link,$sql);
$num = mysqli_num_rows($result);//函数返回结果集中行的数量
//判断是否登录后显示或跳转
if($num){
echo '登录成功';
}else{
echo'登录失败';
}
mysqli_close($link);//关闭数据库
?>`
* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
* 10
* 11
* 12
* 13
* 14
* 15
* 16
* 17
* 18
* 19
* 20
* 21
* 22
* 23
* 24
register.php代码:
`<?php
header("content-type:text/html;charset=utf-8");
//连接数据库
$link = mysqli_connect("localhost","pay_com_cn","pay_com_cn","pay_com_cn");
if (!$link) {
die("连接失败: " . mysqli_connect_error());
}
//接收$_POST用户名和密码
$username=$_POST['username'];
$password=$_POST['password'];
//查看表user用户名是否存在或为空
$sql_select = "SELECT * FROM user WHERE username = '$username'";
//result必需规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。
$select = mysqli_query($link,$sql_select);
$num = mysqli_num_rows($select);//函数返回结果集中行的数量
if($username == "" || $password == "")
{
echo "请确认信息完整性";
}else if($num){
echo "已存在用户名";//已存在账户名输出错误
}else{
$sql="insert into user(username,password) values('$username','$password')";
$result=mysqli_query($link,$sql);
//判断是否注册后显示内容
if(!$result)
{
echo "注册不成功!"."<br>";//输出错误
echo "<a href='index.php'>返回</a>";//超链接到首页
}
else
{
echo "注册成功!"."<br/>";//输出成功
echo "<a href='index.hphp'>立刻登录</a>";//超链接到首页
}
}
?>`
* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
* 10
* 11
* 12
* 13
* 14
* 15
* 16
* 17
* 18
* 19
* 20
* 21
* 22
* 23
* 24
* 25
* 26
* 27
* 28
* 29
* 30
* 31
* 32
* 33
* 34
* 35
* 36
* 37
最后附上本文用到的mysql表
以上就是一个简单的PHP注册登录页面了~
非常感谢大家的关注支持~
关于报错:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in
的处理请点击 这里进入
Pycharm专业版下载:https://pan.baidu.com/s/1kGqR5lUOFJLySXFd0zVs_Q 提取码:8888
博主的QQ:1617184046
博主的官网:瞄一眼~
Zhe-wPHPPython
本人会长期更新Python、PHP源码、文章、学习记录、笔记、心得总结等资源~ 免费分享给大家参考学习~ 文章中如有问题希望可以联系QQ1617184046支出~ 感谢大家的支持~
php介绍
PHP即“超文本预处理器”,是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。PHP独特的语法混合了C、Java、Perl以及 PHP 自创的语法。利于学习,使用广泛,主要适用于Web开发领域。