PHP学习笔记(四 实训结束) 实现登录与注册连接数据库
发布时间:2022-09-23 15:53:52 315
相关标签: # html# php# mysql# 数据库# sql
文章目录
- 知识点
- 数据库连接
- 页面停顿跳转
- 获取数据
- login.html
- login.php
- register.html
- register.php
知识点
数据库连接
error_reporting(E_ALL & ~E_DEPRECATED);
header('Content-type:text/html;charset=utf8');
$conn = mysql_connect('localhost','root','root')
or die("<script>alert('连接MySQL失败,请重试!');</script>");
mysql_set_charset('utf8');//5.5以下适用
$select = mysql_select_db('user')
or die("<script>alert('连接数据库失败,请重试!');</script>");
页面停顿跳转
echo '<meta http-equiv="refresh" content=3;url=http://localhost:8081/login.html>';
获取数据
$query = mysql_query($sql)
or die("<script>alert('查询失败,请重试!');</script>");
$t = mysql_fetch_array($query,MYSQL_ASSOC);//此时$t是一个数组
login.html
<html>
<head>
<meta charset = "utf-8">
<title>
登录
</title>
</head>
<div style = "height:600px;width:300px;margin:0 auto;text-align:center">
<meta charset = "utf-8">
<div>
<form method = "post" action = "login.php">
用户名:<input type = "text" name = "name" placeholder = "请输入名称"><br>
密码:<input type = "password" name = "password" placeholder = "请输入名称"><br>
<input type = "submit" value = "提交">
<input type = "reset" value = "重置">
</form>
</div>
</div>
</html>
login.php
register.html
<html>
<head>
<meta charset = "utf-8">
<title>
注册
</title>
</head>
<div style = "height:600px;width:300px;margin:0 auto;text-align:center">
<meta charset = "utf-8">
<div>
<form method = "post" action = "register.php">
用户名:<input type = "text" name = "name" placeholder = "请输入名称"><br>
密码:<input type = "password" name = "password" placeholder = "请输入密码"><br>
确认密码:<input type = "password" name = "repassword" placeholder = "请再次输入密码"><br>
邮箱:<input type = "email" name = "email" placeholder = "请输入邮箱"><br>
<input type = "submit" value = "提交">
<input type = "reset" value = "重置">
</form>
</div>
</div>
</html>
register.php
文章来源: https://blog.51cto.com/u_15700954/5426726
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报