php+mysql简易留言板,实现注册,登录,注销,查看留言,删除留言

1,index.html登录页面

代码:

<!doctype html>

<html>

<head>

<meta charset="UTF-8">

<title>登陆</title>

<style type="text/css">

*{

margin: 0;

padding: 0;

}

div{

width: 200px;

height: 200px;

}

.center-in-center{

position: absolute;

top: 50%;

left: 50%;

-webkit-transform: translate(-50%, -50%);

-moz-transform: translate(-50%, -50%);

-ms-transform: translate(-50%, -50%);

-o-transform: translate(-50%, -50%);

transform: translate(-50%, -50%);

}

</style>

</head>

<body bgcolor="#d0d0d0">

<div class="center-in-center">

<h2 align="center">用户登录</h2>

<form name="dl" action="dl.php" method="post">

<p align="center">用户名:<input type=text name="name"></p>

<p align="center">密码:<input type=password name="password"></p>

<p align="center"><input type="submit" name="denglu" value="登录"></p>

</form>

<form name="ze" action="zc.html" method="post" >

<p align='center'><input type="submit" name="zhuce" value="注册" > </p>

</form> </div>

</body>

</html>

css样式用来将页面标签居中对齐

2,建立数据库连接文件conn.php

<?php

$server="localhost:3306";//主机的IP地址,你也可以选填127.0.0.1

$db_username="root";//数据库用户名

$db_password="root";//数据库密码

$con = mysqli_connect($server,$db_username,$db_password);//链接数据库

if(!$con){

die("can't connect".mysql_error());//如果链接失败输出错误

}

mysqli_select_db($con,'zhuce');//选择数据库

?>

3,登录后端验证dl.php

<?php

header("Content-Type: text/html; charset=utf8");

if(!isset($_POST["denglu"])){

echo "错误执行";

echo "<script>                       setTimeout(function(){window.location.href='index.html';},2000);                  </script>";}//检测是否有submit操作

include('conn.php');//链接数据库

$name = $_POST['name'];//post获得用户名表单值

$passowrd = $_POST['password'];//post获得用户密码单值

if ($name && $passowrd){//如果用户名和密码都不为空

$sql = "select * from t1 where username = '$name' and password='$passowrd'";//检测数据库是否有对应的username和password的sql

$result = mysqli_query($con,$sql);//执行sql

$rows=mysqli_num_rows($result);//返回一个数值

if($rows){//0 false 1 true

echo $rows;

header("refresh:0;url=ly.html");//如果成功跳转至welcome.html页面

exit;

}

else{

echo "<script>alert('用户名或密码错误,点击确定返回!');</script>";

header("refresh:0;url=index.html");

}

}else{//如果用户名或密码有空

echo "<script>alert('用户名或不能为空,点击确定返回!');</script>";

header("refresh:0;url=index.html");

}

mysqli_close($con);//关闭数据库

?>

4,注册前端zc.html,

代码:

<!DOCTYPE html>

<html>

<head>

<title>注册</title>

<meta charset="utf-8">

<style type="text/css">

*{

margin: 0;

padding: 0;

}

div{

width: 200px;

height: 200px;

}

.center-in-center{

position: absolute;

top: 50%;

left: 50%;

-webkit-transform: translate(-50%, -50%);

-moz-transform: translate(-50%, -50%);

-ms-transform: translate(-50%, -50%);

-o-transform: translate(-50%, -50%);

transform: translate(-50%, -50%);

}

</style>

</head>

<body bgcolor="#d0d0d0">

<div class="center-in-center">

<h2 align="center">用户注册</h2>

<form action="zhuce.php" method="post">

<p align='center'>用户账户:<input id="user" name="user" type="text" placeholder="用户名"/></p>

<p align='center'>注册密码:<input id="psd1" name="psd1" type="password" placeholder="密码"/></p>

<p align='center'>重复密码:<input id="psd2" name="psd2" type="password" placeholder="验证密码"/></p>

<p align='center'>注册邮箱:<input id="eml" name="eml" type="email" placeholder="邮箱"/></p>

<p align='center'><input id="sbt" name="sbt" type="submit" placeholder="提交"/></p>

</form>

</div>

</body>

</html>

5,注册后端验证zhuce.php

代码:

<?php

header("content-type:text/html;charset=utf-8");

session_start();

$name=$_POST['user'];

$pwd=$_POST['psd1'];

$repwd=$_POST['psd2'];

$email=$_POST['eml'];

if(empty($name)||empty($pwd)||empty($repwd)||empty($email)){

echo "<script>alert('你逗我?信息输入没完整');</script>";

echo "<script>window.location='zc.html';</script>";

}else

if ($pwd!=$repwd) {

echo"<script>alert('两次密码输入不一致,请重新输入');</script>";

echo"<script>location='zc.html'</script>";

}else{

include('conn.php');

$sql1 = "SELECT * FROM t1 WHERE username='$name'";

$result = mysqli_query($con,$sql1);

$rows = mysqli_num_rows($result);

if($rows>0) {

echo "<script>alert('用户名已经有人注册了,重新注册一个吧')</script>";

echo "<script>window.location='zc.html'</script>";

}

else {

echo "用户名可用\n".'<br>';

mysqli_query($con,"set names utf8");

$sqlinsert="insert into t1(username,password,email) values('{$name}','{$pwd}','{$email}')";

$result=mysqli_query($con,$sqlinsert);

if(! $result )

{

die('Could not enter data: ' . mysqli_error());

}

echo "恭喜你注册成功".'<br>';

echo '用户名:'.$name.'<br>';

echo '密码:'.md5($pwd).'<br>';

echo '注册邮箱:'.$email.'<br>';

echo "正在返回登录界面,请稍后~";

header("refresh:2;url=index.html");

}

}

mysqli_close($con);

?>

6,登录之后留言界面,前端,ly.html

代码:

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>

php留言板

</title>

<style>

p,textarea{vertical-align:top;}

</style>

</head>

<body bgcolor="#d0d0d0">

<h2 align="center">请留言</h2>

<form action="ly.php" method="post" align='center'>

<p align="center">姓名:<input type="text" name="username" /></p>

<p align="center">留言:<textarea cols="30" rows="5" name="comment" /></textarea></p>

<input type="submit" value="提交">

</form>

<form action="chakan.php" method="post" align='center'>

<input type="submit" name="chakan" value="查看留言" >

</form>

<form action="index.html" method="post" align='center'>

<input type="submit" name="zhuxiao" value="注销" >

</form>

</body>

</html>

7,留言页面后端验证,ly.php

代码:

<?php

header("Content-Type: text/html; charset=utf8");

$user = $_POST['username'];

$comment = $_POST['comment'];

print_r($_POST);

if(empty($user)||empty($comment)){

echo "<script>alert('姓名或内容没输入,请输入好后提交!');</script>";

echo "<script>window.location='ly.html';</script>";

}

else{

include('conn.php');

$sql="insert into t2(username,comment) values('$user','$comment')";

$db=mysqli_select_db($con,'zhuce');

if($db){

$result = mysqli_query($con,$sql);

echo "<script>alert('留言成功');</script>";

header("refresh:0;url=ly.html");

}

else{

echo "留言失败!";

echo mysqli_errno($con);

}

}

mysqli_close($con);

?>

8,查看留言,chakan.php

代码:

<?php

echo "<body bgcolor='#d0d0d0'>";

include('conn.php');

$sql="select * from t2";

$db=mysqli_select_db($con,'zhuce');

$result = mysqli_query($con,$sql);

$array=array();

echo "<h2 align='center'>所有留言</h2>";

echo '<table border="1" align="center"><td>用户</td><td>给你的留言</td>';

while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))

{

echo "<tr><td> {$row['username']}</td> ".

"<td>{$row['comment']} </td> ".

"</tr>";

}

echo '</table>';

mysqli_close($con);

echo '<p><form action="ly.html" method="post" accept-charset="utf-8" align="center"><td><input type="submit" name="fanhui" value="点击返回"></form></p>';

echo '<p><form action="del.php" method="post" accept-charset="utf-8" align="center"><input type="submit" name="shanchu" value="删除留言"></form></p>';

echo "</body>";

?>

9,删除留言,del.php

<html>

<head>

<title>删除留言</title>

</head>

<body bgcolor="#d0d0d0">

<h2 align="center">请找到要删除的留言,点击“删除”</h2>

<?php

include('conn.php');

$sql = "select * from t2";

mysqli_select_db($con,'zhuce');

$result = mysqli_query($con,$sql);

echo '<table border="1" align="center"><tr><td>用户</td><td>给你留言</td></tr>';

while($attr = mysqli_fetch_array($result))

{

echo "<tr>

<td>{$attr[1]}</td>

<td>{$attr[1]}</td>

<td><a onclick=\"return confirm('确定删除么')\" href='delete.php?code={$attr[0]}'>删除</a></td>

</tr>";

}

echo "</table>";

echo '<p><form action="chakan.php" method="post" align="center">

<input type="submit" name="fh" value="点击返回">

</form></p>';

?>

</body>

</html>

10,确定删除,delete.php

<?php

include('conn.php');

$code = $_GET["code"];

$sql = "delete from t2 where id = '{$code}'";

mysqli_select_db( $con, 'zhuce' );

$retval = mysqli_query( $con, $sql );

if(! $retval )

{

die('数据删除失败: ' . mysqli_error($con));

}

echo "数据删除成功,马上返回!";

mysqli_close($con);

header("refresh:1;url=del.php");

?>

11,数据库文件,zhuce.sql

/*

Navicat Premium Data Transfer

Source Server         : localhost_3306

Source Server Type    : MySQL

Source Server Version : 50726

Source Host           : localhost:3306

Source Schema         : zhuce

Target Server Type    : MySQL

Target Server Version : 50726

File Encoding         : 65001

Date: 12/10/2019 18:51:57

*/

SET NAMES utf8mb4;

SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------

-- Table structure for t1

-- ----------------------------

DROP TABLE IF EXISTS `t1`;

CREATE TABLE `t1`  (

`username` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,

`password` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,

`email` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL

) ENGINE = MyISAM CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------

-- Records of t1

-- ----------------------------

INSERT INTO `t1` VALUES ('1111', '111', '1111@qq.com');

INSERT INTO `t1` VALUES ('11111', '111', '1111@qq.com');

INSERT INTO `t1` VALUES ('sym', 'zzz', 'zzz@qq.com');

INSERT INTO `t1` VALUES ('111', '111', '1111@qq.com');

INSERT INTO `t1` VALUES ('222', '222', '222@a.com');

INSERT INTO `t1` VALUES ('asd', 'asd', 'asd@123.com');

INSERT INTO `t1` VALUES ('sym945', 'zxc', 'zxc@qq.com');

INSERT INTO `t1` VALUES ('555555', '555', '555@qq.com');

INSERT INTO `t1` VALUES ('syms', 'sss', 'sss@qq.com');

INSERT INTO `t1` VALUES ('zxzx', 'zxzx', 'zx@qq.co');

-- ----------------------------

-- Table structure for t2

-- ----------------------------

DROP TABLE IF EXISTS `t2`;

CREATE TABLE `t2`  (

`id` bigint(20) NOT NULL AUTO_INCREMENT,

`username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,

`comment` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,

PRIMARY KEY (`id`) USING BTREE

) ENGINE = MyISAM AUTO_INCREMENT = 21 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------

-- Records of t2

-- ----------------------------

INSERT INTO `t2` VALUES (19, '123', '123123');

INSERT INTO `t2` VALUES (20, '22333', '22333');

SET FOREIGN_KEY_CHECKS = 1;

2019-10-12,html+php+mysql简单留言板,作业的更多相关文章

  1. 原生JS实现简单留言板功能

    原生JS实现简单留言板功能,实现技术:css flex,原生JS. 因为主要是为了练手js,所以其中布局上的一些细节并未做处理. <!DOCTYPE html> <html lang ...

  2. php+mysql简单留言,适合新手

    <html> <head> <title> php留言板 </title> <style> p,textarea{vertical-alig ...

  3. Django入门3 简单留言板项目案例及mysql驱动的安装配置

    新建jangostart项目 使用manager.py新建app即单独的应用 创建一个message应用 manage.py@djangostart > startapp message 如果a ...

  4. PHP实现简单留言板

    最近学习了下PHP基础,这里做一个简单的留言板,算是对PHP和MySQL的使用做一个整体的练习吧,不遇到问题总感觉学不到东西. 截图如下: 总结: 1>数据库的简单操作,数据库的增删改查: 2. ...

  5. Problem A. 最近公共祖先 ———2019.10.12

    我亲爱的学姐冒险跑去为我们送正解 但是,,,, 阿龙粗现了! cao,, 考场期望得分:20   实际得分:20 Problem A. 最近公共祖先 (commonants.c/cpp/pas) 最近 ...

  6. jQuery进阶第三天(2019 10.12)

    一.原生JS快捷的尺寸(属性)(注意这些属性的结果 不带PX单位) clientWidth/clientHeight  =====> 获得元素content+padding的宽/高: offse ...

  7. Problem C. 欧皇 ————2019.10.12

    题目: 再次感激土蛋 #include <bits/stdc++.h> using namespace std; typedef long long ll; ; ll C[][]; voi ...

  8. Problem B. 即时战略 ———2019.10.12

    题目:   代码~:感谢土蛋 #include <iostream> #include <cstring> #include <cmath> #include &l ...

  9. 【2019.10.30】SDN上机第1次作业

    用字符命令搭建如下拓扑,要求写出命令 题目一: 字符命令如下: 题目二: 字符命令如下: 利用可视化工具搭建如下拓扑 要求支持OpenFlow 1.0 1.1 1.2 1.3,设置h1(10.0.0. ...

随机推荐

  1. redis集群之Codis

    在大数据高并发场景下,单个 Redis 实例往往会显得捉襟见肘.首先体现在内存上,单个 Redis 的内存不宜过大,内存太大会导致 rdb 文件过大,进一步导致主从同步时全量同步时间过长,在实例重启恢 ...

  2. C#控件的简单应用

    listview 创建columns: ImageList imgList = new ImageList(); imgList.ImageSize = , ); FaceListview.Small ...

  3. Python+requests+unittest+excel实现接口自动化测试框架(摘录)

    一.框架结构:  工程目录 二.Case文件设计 三.基础包 base 3.1 封装get/post请求(runmethon.py) 1 import requests 2 import json 3 ...

  4. 关于RocketMQ消息消费与重平衡的一些问题探讨

    其实最好的学习方式就是互相交流,最近也有跟网友讨论了一些关于 RocketMQ 消息拉取与重平衡的问题,我姑且在这里写下我的一些总结. ## 关于 push 模式下的消息循环拉取问题 之前发表了一篇关 ...

  5. linux shell 小技能

    环境: [root@test ~]# cat /etc/redhat-release CentOS release 6.5 (Final) [root@test ~]# uname -a Linux ...

  6. ITester软件测试小栈,快来点击领取你的能量值!

    日供一卒,功不唐捐,这不是一个非正常更新的ITester软件测试小栈,不定期分享软件测试相关,包括功能.接口.自动化.性能.专项.测试开发,简历指点,面试助攻,群而不党,和而不同,如趋同,且同行.

  7. 一文学会Go语言

    go语言随手记 -- go语言定位于高并发服务端程序 1.基本数据类型 boolstringint int8 int16 int32 int64uint uint8 uint16 uint32 uin ...

  8. 爬虫学习--Requests库详解 Day2

    什么是Requests Requests是用python语言编写,基于urllib,采用Apache2 licensed开源协议的HTTP库,它比urllib更加方便,可以节约我们大量的工作,完全满足 ...

  9. 手把手带你实战下Spring的七种事务传播行为

    目录 本文目录 一.什么是事务传播行为? 二.事务的7种传播行为 三.7种传播行为实战 本文介绍Spring的七种事务传播行为并通过代码演示下. 本文目录 一.什么是事务传播行为? 事务传播行为(pr ...

  10. linux 设置固定ip和dns

    目录 1. centos 1.1 ifconfig 查看网卡名称 1.2 设置固定ip和dns 1.3 重启网络 2. ubuntu 2.1 ifconfig 查看网卡名称 2.2 设置固定ip和dn ...