php真的挺好玩的!

先写出前台页面index.php:

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
label{
width: 60px;
display: inline-block;
text-align: right;
margin: 0 10px 0 0;
}
@media screen and (min-width: 360px) and (max-width: 767px) {
.content-div{
width: 90%;
margin: 5% auto;
}
.form-ele{
width: 50%;
margin: auto;
}
.content-div h2.head-title{
text-align: center;
}
.form-ele p input[type="text"]{
width: 80%;
}
.f-messages{
width: 80%;
resize: none;
height: 100px;
padding: 10px;
box-sizing: border-box;
}
.submit-btn{
width: 90px;
height: 35px;
background: rgba(0,233,2,0.4);
border: none;
color: block;
font-size: 1.2em;
cursor: pointer;
-webkit-transition:background 0.5s;
-ms-transition:background 0.5s;
-o-transition:background 0.5s;
transition:background 0.5s;
}
.submit-btn:hover{
background: rgba(0,233,2,0.7);
}
}
@media screen and (min-width: 768px) and (max-width: 1199px){
.content-div{
width: 90%;
margin: 5% auto;
}
.form-ele{
width: 50%;
margin: auto;
}
.content-div h2.head-title{
text-align: center;
}
.form-ele p input[type="text"]{
width: 70%;
}
.f-messages{
width: 80%;
resize: none;
height: 100px;
padding: 10px;
box-sizing: border-box;
}
.submit-btn{
width: 90px;
height: 35px;
background: rgba(0,233,2,0.4);
border: none;
color: block;
font-size: 1.2em;
cursor: pointer;
-webkit-transition:background 0.5s;
-ms-transition:background 0.5s;
-o-transition:background 0.5s;
transition:background 0.5s;
}
.submit-btn:hover{
background: rgba(0,233,2,0.7);
}
}
@media screen and (min-width: 1200px) and (max-width: 1365px) {
.content-div{
width: 90%;
margin: 5% auto;
}
.form-ele{
width: 50%;
margin: auto;
}
.content-div h2.head-title{
text-align: center;
}
.form-ele p input[type="text"]{
width: 80%;
}
.f-messages{
width: 80%;
resize: none;
height: 100px;
padding: 10px;
box-sizing: border-box;
}
.submit-btn{
width: 90px;
height: 35px;
background: rgba(0,233,2,0.4);
border: none;
color: block;
font-size: 1.2em;
cursor: pointer;
-webkit-transition:background 0.5s;
-ms-transition:background 0.5s;
-o-transition:background 0.5s;
transition:background 0.5s;
}
.submit-btn:hover{
background: rgba(0,233,2,0.7);
}
}
@media screen and (min-width: 1366px) and (max-width: 1920px) {
.content-div{
width: 90%;
margin: 5% auto;
}
.form-ele{
width: 50%;
margin: auto;
}
.content-div h2.head-title{
text-align: center;
}
.form-ele p input[type="text"]{
width: 80%;
}
.f-messages{
width: 80%;
resize: none;
height: 100px;
padding: 10px;
box-sizing: border-box;
}
.submit-btn{
width: 90px;
height: 35px;
background: rgba(0,233,2,0.4);
border: none;
color: block;
font-size: 1.2em;
cursor: pointer;
-webkit-transition:background 0.5s;
-ms-transition:background 0.5s;
-o-transition:background 0.5s;
transition:background 0.5s;
}
.submit-btn:hover{
background: rgba(0,233,2,0.7);
}
}
</style>
</head>
<body> <div class="content-div">
<h2 class="head-title">留言</h2>
<form action="add.php" method="post" class="form-ele">
<p>
<label for="names">姓名:</label><input id="names" type="text" name="names">
</p>
<p>
<label for="qq">QQ:</label><input id="qq" type="text" name="qq">
</p>
<p>
<label for="email">email:</label><input id="email" type="text" name="email">
</p>
<p>
<label for="messages">留言:</label><textarea id="messages" name="messages" class="f-messages"></textarea>
</p>
<p style="text-align: center;">
<input type="submit" name="sub" value="提交" class="submit-btn">
</p>
</form>
</div> </body>
</html>

效果:

我们要获取的是页面表单POST上来的内容,表单action的目标是add.php,add.php与index.php放在同一目录下(譬如:d:wamp/www/phpfile,服务器用wamp就可以测试)。

下面是add.php的代码:

 <?php 

         if($_POST['names']){

             $host="localhost:3306";//本地服务器主机地址
$user = "root";//用户名
$password = "";//密码
$dbname = "phpbook";//数据库名字
$id = mysqli_connect($host,$user,$password,$dbname);//连接数据库,并将结果存在$id中
mysqli_query($id,"set names utf-8");//设置编码
mysqli_select_db($id,$dbname);//选择数据库
$names = $_POST["names"];//获取index.php表单中<input type="text" name="names">的内容
$qq = $_POST["qq"];//同上
$email = $_POST["email"];
$messages = $_POST["messages"];
$sql = "insert into users(names,qq,email,messages) values('$names','$qq','$email','$messages')";//sql语句,将获取的内容插入数据库
mysqli_query($id,$sql);//执行数据库语句 if($result = mysqli_query($id,"select * from users;")){//查询数据库中users中所有内容,并将结果存在$result中
echo "<table border='0'>
<tr>
<th>姓名</th>
<th>qq</th>
<th>email</th>
<th>留言内容</th>
</tr>";
while($row = mysqli_fetch_array($result)){//获取内容存在数组中
echo " <tr>
<td>".$row['names']."
</td>
<td>".$row['qq']."
</td>
<td>".$row['email']."
</td>
<td>".$row['messages']."
</td>
</tr>
";
}
echo "</table>";
}else{
echo "添加失败";
}
} ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>显示留言</title>
<style>
table{
border:none;
border-spacing:0;
width: 90%;
margin: auto;
}
</style>
</head>
<body> </body>
</html>

效果:

php实现留言功能的更多相关文章

  1. 我的第一个jsp程序-实现注册登录留言功能

    1,注册功能,包括两个页面 zhuce.jsp注册页面 <%@ page language="java" contentType="text/html; chars ...

  2. 用 JS + LeanCloud 给网页添加数据库(留言功能)

    记录给自己网页添加留言功能的过程. 使用工具:LeanCloud,一个自带数据库和增删改查(CRUD)功能的后台系统. 1 在JS中引入LeanCloud官方库 在LeanCloud注册并添加应用的步 ...

  3. 微信小程序 「柒留言」 — 实现微信公众号留言功能(限时免费入驻,建议收藏)

    「柒留言」小程序留言助手使用指南(接近原生界面) 前言 从去年 3 月以后新公众号就没得留言功能了,新申请的微信公众号没有留言功能,没有留言就无法跟读者进行互动,写出去的文章得不到反馈,着实感觉有蛮难 ...

  4. FastAPI(七十)实战开发《在线课程学习系统》接口开发--留言功能开发

    在之前的文章:FastAPI(六十九)实战开发<在线课程学习系统>接口开发--修改密码,这次分享留言功能开发 我们能梳理下对应的逻辑 1.校验用户是否登录 2.校验留言的用户是否存在 3. ...

  5. Node.js 博客实例(六)留言功能

    原教程https://github.com/nswbmw/N-blog/wiki/_pages的第六章,因为版本号等的原因,在原教程基础上稍加修改就可以实现. 实现用户给文章留言的功能,留言保存在数据 ...

  6. javascript实现留言功能

    原理: 1.用户在留言框输入留言 2.利用textarea的value属性获取到用户输入的留言 3.动态创建一个li 4.将获取的留言打包成html存到li中 5.根据需要添加删除留言.统计留言数量等 ...

  7. wordpress如何批量关闭旧日志留言功能

    于一些wordpress技术博客或者其他wordpress博客来说,一些旧日志的内容可能已经过时了,但是一些读者,还是对一些问题“纠缠不清”或者“喋喋不休”,怎么办,把留言关了就好了: UPDATE ...

  8. html留言功能

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  9. JS小练习 留言功能

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

随机推荐

  1. 人人都是 DBA(III)SQL Server 调度器

    在 SQL Server 中,当数据库启动后,SQL Server 会为每个物理 CPU(包括 Physical CPU 和 Hyperthreaded)创建一个对应的任务调度器(Scheduler) ...

  2. PLoP(Pattern Languages of Programs,程序设计的模式语言)

    2014/8/1 12:24:21潘加宇 http://www.umlchina.com/News/Content/340.htmPloP大会2014即将举行 PLoP(Pattern Languag ...

  3. css 常见时间轴的做法(————————————————时间轴——————————————————)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. atitit 英文与中文与阿拉伯文的简化解决方案.docx

    atitit 英文与中文与阿拉伯文的简化解决方案.docx 1. 英文与中文与阿拉伯文的简化意义1 2. 简化的主要方法分类2 2.1. 同音替代法(比如o2o)2 2.2. 符号法(比如英文i18n ...

  5. Atiti  attilax主要成果与解决方案与案例rsm版 v4

    Atiti  attilax主要成果与解决方案与案例rsm版 v4 版本历史记录1 1. ##----------主要成果与解决方案与 参与项目1 ###开发流程与培训系列1 #-----组织运营与文 ...

  6. 阿里云配置mysql navcat远程连接

    默认是不能用客户端远程连接的,阿里云提供的help.docx里面做了设置说明,mysql密码默认存放在/alidata/account.log 首先登录: mysql -u root -h local ...

  7. SpringBoot常用配置简介

    SpringBoot常用配置简介 1. SpringBoot中几个常用的配置的简单介绍 一个简单的Spring.factories # Bootstrap components org.springf ...

  8. unity生成WP工程后ExtendedSplashImage显示不正确的问题

    这个bug我已经彻底无语了,居然这么久都没有fix. 解决方法如下: <SwapChainPanel x:Name="DXSwapChainPanel"> <Gr ...

  9. jqGrid实现当前页列合计与总计

    当前页列合计    js代码如下:   ... footerrow: true, gridComplete: function () { var rowNum = parseInt($(this).g ...

  10. ssh(sturts2_spring_hibernate) 框架搭建之hibernate2

    一.今天要进行解答的是对上次hibernate1进行进一步的完善,这次第一是进一步使用spring注入一个SessionFactory实例,避免了自己new实例:第二是应用数据库池(c3p0). 二. ...