当前位置:网站首页>PHP+MySQL 制作留言板
PHP+MySQL 制作留言板
2022-04-23 04:46:00 【yizecellophp】
表单 index.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>留言板</title>
</head>
<body>
<span>留言板</span>
<div>
<form action="liuyan.php" method="post">
<table>
<tr>
<td><input type="text" name="user" placeholder="网名"/></td>
</tr>
<tr>
<td><textarea name="contern" cols="50" rows="5" placeholder="留言内容"></textarea></td>
</tr>
<input type="submit" value="发表留言"/>
</form>
</div>
<div>
<?php
$cc=mysqli_connect("localhost","root",""); //连接MySQL数据库
$db=mysqli_select_db($cc,"test"); //选择数据库
$sql="select * from liuyan"; //查看liuyan表所有的数据
$re=mysqli_query($cc,$sql); //执行SQL语句
echo "<table width='800'>";
echo "<tr><th>留言用户</th><th>留言内容</th><th>留言时间</th></tr>";
while($r=mysqli_fetch_array($re,MYSQLI_BOTH)){ //循环输出数据
echo "<tr><td>".$r['name']."</td><td>".$r['content']."</td><td>".$r['time']."</td></tr>";
}
echo "</table>";
?>
</div>
</body>
</html>
MySQL 数据库表内容
PHP处理页面 liuyan.php
<?php
date_default_timezone_set("Asia/Shanghai"); //设置时区:东八区
$c=$_POST["contern"]; //获取表单提交过来的contern的值
if(empty($c)){ //如果$c为空
echo "<script type='text/javascript'>alert('留言内容不能为空');history.back();</script>"; //弹窗
}else{
$u=$_POST["user"]; //获取表单提交过来的user的值
if(empty($u)){ //如果$u为空
echo "<script type='text/javascript'>alert('留言用户不能为空');history.back();</script>"; //弹窗
}else{
$t=date("Y-m-d,H:m:s"); //获取时间
$c=trim($c); //去掉两端的空格
$c=htmlspecialchars($c); //把html标签转换为实体
$c=addslashes($c); //转义
$cc=mysqli_connect("localhost","root",""); //连接MySQL数据库
$db=mysqli_select_db($cc,"test"); //选择test数据库
$sql="insert into liuyan (name,content,time) values ('$u','$c','$t')";
$r=mysqli_query($cc,$sql); //执行SQL语句
if($r){ //如果SQL语句执行成功
echo "<script type='text/javascript'>alert('留言成功!');history.back();</script>"; //弹窗
}else{
echo "<script type='text/javascript'>alert('留言失败');history.back();</script>"; //弹窗
}
mysqli_close($cc); //关闭数据库的连接
}
}
?>
注意!两份php页面都要修改数据库连接信息!
版权声明
本文为[yizecellophp]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Celloda/article/details/124291208
边栏推荐
- Unity3d practical skills - theoretical knowledge base (I)
- Summary of MySQL de duplication methods
- The 14th issue of HMS core discovery reviews the long article | enjoy the silky clip and release the creativity of the video
- 补充番外14:cmake实践项目笔记(未完待续4/22)
- Leetcode002 -- inverts the numeric portion of a signed integer
- Youqilin 22.04 lts version officially released | ukui 3.1 opens a new experience
- Practice and exploration of knowledge map visualization technology in meituan
- [pytoch foundation] torch Split() usage
- MySQL queries users logged in for at least N consecutive days
- Open the past and let's start over.
猜你喜欢
Experience summary and sharing of the first prize of 2021 National Mathematical Modeling Competition
PIP3 installation requests Library - the most complete pit sorting
Flink's important basics
Introduction to raspberry pie 3B - system installation
Recommended scheme of national manufactured electronic components for intelligent electronic scales
Supplement: Annotation
POI export message list (including pictures)
Youqilin 22.04 lts version officially released | ukui 3.1 opens a new experience
QML进阶(五)-通过粒子模拟系统实现各种炫酷的特效
Pixel 5 5g unlocking tutorial (including unlocking BL, installing edxposed and root)
随机推荐
FAQ of foreign lead and alliance Manager
Painless upgrade of pixel series
QML advanced (V) - realize all kinds of cool special effects through particle simulation system
2020 is coming to an end, special and unforgettable.
List remove an element
Leetcode006 -- find the longest common prefix in the string array
Differences among electric drill, electric hammer and electric pick
win10, mysql-8.0.26-winx64. Zip installation
Programmers complain: I really can't live with a salary of 12000. Netizen: how can I say 3000
What is the meaning of load balancing
Code007 -- determine whether the string in parentheses matches
Pixel 5 5g unlocking tutorial (including unlocking BL, installing edxposed and root)
What is the thirty-six plan
Simply drag objects to the item bar
使用model.load_state_dict()时,出现AttributeError: ‘str‘ object has no attribute ‘copy‘
zynq平臺交叉編譯器的安裝
Ali's ten-year technical experts jointly created the "latest" jetpack compose project combat drill (with demo)
Opencv + clion face recognition + face model training
Spark small case - RDD, spark SQL
Unity rawimage background seamlessly connected mobile