php实现留言功能
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实现留言功能的更多相关文章
- 我的第一个jsp程序-实现注册登录留言功能
1,注册功能,包括两个页面 zhuce.jsp注册页面 <%@ page language="java" contentType="text/html; chars ...
- 用 JS + LeanCloud 给网页添加数据库(留言功能)
记录给自己网页添加留言功能的过程. 使用工具:LeanCloud,一个自带数据库和增删改查(CRUD)功能的后台系统. 1 在JS中引入LeanCloud官方库 在LeanCloud注册并添加应用的步 ...
- 微信小程序 「柒留言」 — 实现微信公众号留言功能(限时免费入驻,建议收藏)
「柒留言」小程序留言助手使用指南(接近原生界面) 前言 从去年 3 月以后新公众号就没得留言功能了,新申请的微信公众号没有留言功能,没有留言就无法跟读者进行互动,写出去的文章得不到反馈,着实感觉有蛮难 ...
- FastAPI(七十)实战开发《在线课程学习系统》接口开发--留言功能开发
在之前的文章:FastAPI(六十九)实战开发<在线课程学习系统>接口开发--修改密码,这次分享留言功能开发 我们能梳理下对应的逻辑 1.校验用户是否登录 2.校验留言的用户是否存在 3. ...
- Node.js 博客实例(六)留言功能
原教程https://github.com/nswbmw/N-blog/wiki/_pages的第六章,因为版本号等的原因,在原教程基础上稍加修改就可以实现. 实现用户给文章留言的功能,留言保存在数据 ...
- javascript实现留言功能
原理: 1.用户在留言框输入留言 2.利用textarea的value属性获取到用户输入的留言 3.动态创建一个li 4.将获取的留言打包成html存到li中 5.根据需要添加删除留言.统计留言数量等 ...
- wordpress如何批量关闭旧日志留言功能
于一些wordpress技术博客或者其他wordpress博客来说,一些旧日志的内容可能已经过时了,但是一些读者,还是对一些问题“纠缠不清”或者“喋喋不休”,怎么办,把留言关了就好了: UPDATE ...
- html留言功能
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...
- JS小练习 留言功能
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
随机推荐
- ThoughtWorks持续集成平台GO开源了
ThoughtWorks 持续集成平台Go最近宣布开源了.其基于Apache 2.0 开源协议. Go下载地址为http://www.go.cd/download/. 下面是几张来自官方的视图: GO ...
- VS开发中的代码编写小技巧——避免重复代码编写的几种方法
上一篇文章中程序员的幸福生活--有你的日子,每天都是情人节,收到了大家的很多好评.鼓励和祝福,非常感动,真诚的谢谢大家.也希望每个朋友都能保持一个积极向上的心态,去迎接丰富多彩的人生. 在开发过程中, ...
- Java枚举类型getClass和getDeclaringClass区别(未完待续)
Java中的枚举类型有getClass()和getDeclaringClass()两个方法,在通常情况下这两个方法返回的类型一样,在某些场景下会有不同的表现 参照 http://stackoverfl ...
- Visual Studio 2015 速递(4)——高级特性之移动开发
系列文章 Visual Studio 2015速递(1)——C#6.0新特性怎么用 Visual Studio 2015速递(2)——提升效率和质量(VS2015核心竞争力) Visual Studi ...
- Linux初学 - head,tail,grep,sed,yum,find
head 查看文件头部 -n 指定查看行数 默认10行 tail 查看文件尾部 n 指定查看行数 默认10行 Grep 命令 用法大全 . 参数: -I :忽略大小写 -c :打印匹配的行数 -l : ...
- maven install 读取jar包时出错;error in opening zip file
错误信息: [INFO] ------------------------------------------------------------------------ [ERROR] Failed ...
- How Google TestsSoftware - Part Two
In order for the "you buildit, you break it" motto to be real, there are roles beyond the ...
- 理论经典:TCP协议的3次握手与4次挥手过程详解
1.前言 尽管TCP和UDP都使用相同的网络层(IP),TCP却向应用层提供与UDP完全不同的服务.TCP提供一种面向连接的.可靠的字节流服务. 面向连接意味着两个使用TCP的应用(通常是一个客户和一 ...
- 使用jasperreports-5.6.0.jar导致的问题
使用jasperreports-5.6.0.jar导致的问题 Struts2+jasperReport5.6如下设置: <!-- 社员档案 --> <package name=&qu ...
- Account problem-There may be a problem with your account. Please contact us. Sign out
很多人在使用开发者账号AppleID的时候,都会碰到如下问题 There may be a problem with your account. Please contact us. 登录到苹果的开发 ...