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. Apollo学习笔记(一):canbus模块与车辆底盘之间的CAN数据传输过程

    Apollo学习笔记(一):canbus模块与车辆底盘之间的CAN数据传输过程 博主现在从车载自组网信道分配和多跳路由转向了自动驾驶,没啥经验,想快些做出来个Demo还是得站在巨人的肩膀上才行,我选择 ...

  2. Mysql数据库(四)表记录的更新操作

    一.插入表记录 1.使用INSERT...VALUES语句插入新纪录 (1)插入完整数据 mysql> desc tb_manager; +-------+------------------+ ...

  3. 痞子衡嵌入式:飞思卡尔i.MX RTyyyy系列MCU硬件那些事(2.2)- 在串行NOR Flash XIP调试原理

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是飞思卡尔i.MX RTyyyy系列EVK在串行NOR Flash调试的原理. 本文是i.MXRT硬件那些事系列第二篇的续集,在第二篇首集 ...

  4. List<model>需要根据特定字段求差集的实现

    list对象不能直接使用Except等封装好的函数,因为内存地址不一样(还有一些数虽然主数据一致但是update/create信息也不一致,对,我碰到的需求就是这么难受 TOT) 这时候我们的需求很多 ...

  5. Python安装pyinstaller方法,以及将项目生成可执行程序的步骤

    pyinstaller安装方法 前提:确保计算机安装了Python语言环境,并且正确配置了环境变量. 方法一:联网在线自动安装 选择一 Windows OS下进入cmd(命令行窗口) 输入:pip i ...

  6. c#通过libreOffice实现 office文件转pdf文件

    一.安装libreOffice 点击官网下载libreOffice 二.创建一个新的项目LibreOffice 创建一个新的项目,方便后面调用 添加下面代码 public class OfficeCo ...

  7. 几种部署Goku API Gateway的方式,最快一分钟可使用上网关

    本文将介绍几种部署Goku API Gateway的方式,最快一分钟可使用上为网关,详情请看全文. 什么是Goku API Gateway? Goku API Gateway (中文名:悟空 API ...

  8. 《Effective Java》 读书笔记(四) 使用私有构造方法执行非实例化

    在许多时候,我们会写一个类,这个类只是用来提供一些静态方法或静态属性,就好像C++的函数一样,比如 java.lang.Math,java.util.Arrays等,但是有时候这些类的用户可能会在无意 ...

  9. Linux下修改文件权限,所有权

    Linux与Unix是多用户操作系统,所以文件的权限与所有权的实现就显得很有必要:每个文件主要与三组权限打交道,分别是用户(user),用户组(group),其他用户(other) 用户(u)是文件的 ...

  10. [考试反思]0811NOIP模拟测试17:虚无

    (sdfz未参加,也就是一共就51个人) 也不粘具体排名了,只写分数线. []220 []201 []194 [5]181 [10]141 [15]132 [20]122 [25]116 [30]10 ...