php 登录注册

注册代码:register.php

<style type="text/css">
form{
width:300px;
background-color:#EEE0E5;
margin-left:300px;
margin-top:30px;
padding:30px;
}
button{
margin-top:20px;
}
</style>
<form method="post">
<label>用户名:<input type="text" name="name"></label>
<br/><br/>
<label>密码:<input type="password" name="pw"></label>
<br/><br/>
<label>再次输入密码:<input type="password" name="repw"></label>
<button type="submit" name="submit">注册</button>
</form>
<?php
$link = mysqli_connect('localhost', 'root', 'root', 'test');
if (!$link) {
die('Could not connect: ' . mysql_error());
}else {
if (isset($_POST['submit'])){
if ($_POST['pw'] == $_POST['repw']){
$query = "insert into user (name,pw) values('{$_POST['name']}','{$_POST['pw']}')";
$result=mysqli_query($link, $query);
header("Location:login.php");
}else {
echo "<script>alert('两次输入密码不一致!')</script>";
}
}
}
?>

登录代码: login.php

<style type="text/css">
form{
width:300px;
background-color:#EEE0E5;
margin-left:300px;
margin-top:30px;
padding:30px;
}
</style>
<form method="post">
<label>用户名:<input type="text" name="name"></label>
<br/><br/>
<label>密码:<input type="password" name="pw"></label>
<br/><br/>
<button type="submit" name="submit">登录</button>
</form>
<?php
$link = mysqli_connect('localhost', 'root', 'root', 'test');
if (!$link){
echo"<script>alert('数据库连接失败!')</script>";
}else {
if (isset($_POST['submit'])){
$query = "select * from user where name = '{$_POST['name']}' and pw = '{$_POST['pw']}'";
$result = mysqli_query($link, $query);
if (mysqli_num_rows($result) == 1){
header("Location:index.php");
}
}
}
?>
<?php
$link = mysqli_connect('localhost', 'root', 'root', 'test');
if (!$link) {
die('Could not connect: ' . mysql_error());
}else {
if (isset($_POST['submit'])){
if ($_POST['pw'] == $_POST['repw']){
$query = "insert into user (name,pw) values('{$_POST['name']}','{$_POST['pw']}')";
$result=mysqli_query($link, $query);
header("Location:login.php");
}else {
echo "<script>alert('两次输入密码不一致!')</script>";
}
}
}
?>

最新文章

  1. 【原创】kafka producer源代码分析
  2. extjs 箱子布局
  3. selenium+python自动化之xpath定位
  4. python常见环境安装
  5. Java入门到精通——基础篇之面向对象
  6. 2015北京网络赛 H题 Fractal 找规律
  7. Ajax调用asp.net后台代码
  8. django-cookieless 0.7 : Python Package Index
  9. http协议知识整理(转)
  10. Browsing contexts 浏览器上下文
  11. CF 570D. Tree Requests [dsu on tree]
  12. 如何将html特殊字符编码转换成特殊字符_html十进制编码字符转回来
  13. Oracle em 此网站的安全证书存在问题
  14. 解决spring boot JavaMailSender部分收件人错误导致发送失败的问题
  15. Leetcode 240 Search a 2D Matrix II (二分法和分治法解决有序二维数组查找)
  16. Organising the Organisation(uva10766)(生成树计数)
  17. 51nod 1206 Picture 矩形周长求并 | 线段树 扫描线
  18. ZABBIX 2.1.0 发布,分布式系统监控
  19. 四. Jmeter--JDBC 请求
  20. c++(类) this指针

热门文章

  1. 简述移动端开发前端和app间的关系
  2. WSGI 相关的东东(转载)
  3. SENG201 (Software Engineering I) Project
  4. Android平台targetSdkVersion设置及动态权限
  5. char和QChar(Unicode的编码与内存里的值还不是一回事)
  6. python写算法中的栈
  7. java中 16进制字符串 与普通字符串 与 byte数组 之间的转化
  8. group by 用法解析
  9. Linux的发展历史
  10. nodejs:导出Excel和解析导入的Excel