当前位置:网站首页>Making message board with PHP + MySQL
Making message board with PHP + MySQL
2022-04-23 04:52:00 【yizecellophp】
Forms index.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Message board </title>
</head>
<body>
<span> Message board </span>
<div>
<form action="liuyan.php" method="post">
<table>
<tr>
<td><input type="text" name="user" placeholder=" Net name "/></td>
</tr>
<tr>
<td><textarea name="contern" cols="50" rows="5" placeholder=" Message content "></textarea></td>
</tr>
<input type="submit" value=" Leave a message "/>
</form>
</div>
<div>
<?php
$cc=mysqli_connect("localhost","root",""); // Connect MySQL database
$db=mysqli_select_db($cc,"test"); // Select database
$sql="select * from liuyan"; // see liuyan Table all data
$re=mysqli_query($cc,$sql); // perform SQL sentence
echo "<table width='800'>";
echo "<tr><th> Message user </th><th> Message content </th><th> Message time </th></tr>";
while($r=mysqli_fetch_array($re,MYSQLI_BOTH)){ // Loop output data
echo "<tr><td>".$r['name']."</td><td>".$r['content']."</td><td>".$r['time']."</td></tr>";
}
echo "</table>";
?>
</div>
</body>
</html>
MySQL Database table content

PHP Process page liuyan.php
<?php
date_default_timezone_set("Asia/Shanghai"); // Set time zone : East eight
$c=$_POST["contern"]; // Get the submitted form contern Value
if(empty($c)){ // If $c It's empty
echo "<script type='text/javascript'>alert(' The message content cannot be empty ');history.back();</script>"; // Popup
}else{
$u=$_POST["user"]; // Get the submitted form user Value
if(empty($u)){ // If $u It's empty
echo "<script type='text/javascript'>alert(' Message user cannot be empty ');history.back();</script>"; // Popup
}else{
$t=date("Y-m-d,H:m:s"); // Acquisition time
$c=trim($c); // Remove the spaces at both ends
$c=htmlspecialchars($c); // hold html Convert labels to entities
$c=addslashes($c); // escape
$cc=mysqli_connect("localhost","root",""); // Connect MySQL database
$db=mysqli_select_db($cc,"test"); // choice test database
$sql="insert into liuyan (name,content,time) values ('$u','$c','$t')";
$r=mysqli_query($cc,$sql); // perform SQL sentence
if($r){ // If SQL Statement executed successfully
echo "<script type='text/javascript'>alert(' Message success !');history.back();</script>"; // Popup
}else{
echo "<script type='text/javascript'>alert(' Message failed ');history.back();</script>"; // Popup
}
mysqli_close($cc); // Close the connection to the database
}
}
?>
Be careful ! Two copies php The database connection information should be modified on all pages !

版权声明
本文为[yizecellophp]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230445598843.html
边栏推荐
- Recommended scheme for national production of electronic components of wireless keyboard
- Last day of 2017
- Gets all dates between two times
- Spell it! Two A-level universities and six B-level universities have abolished master's degree programs in software engineering!
- Implementation of switching windows and capturing data in selenium mode
- Innovation training (VI) routing
- View analysis of scenic spots in ArcGIS
- Leetcode001 -- returns the subscript of the array element whose sum is target
- List remove an element
- 【数据库】MySQL单表查询
猜你喜欢

POI export message list (including pictures)

New terminal play method: script guidance independent of technology stack

Recommended scheme for national production of electronic components for wireless charging

Introduction to raspberry pie 3B - system installation

【数据库】MySQL基本操作(基操~)

C language: spoof games

Learning Android from scratch -- Introduction

跨境电商 | Facebook 和 Instagram:哪个社交媒体更适合你?

Painless upgrade of pixel series
![[WinUI3]编写一个仿Explorer文件管理器](/img/3e/62794f1939da7f36f7a4e9dbf0aa7a.png)
[WinUI3]编写一个仿Explorer文件管理器
随机推荐
MySQL - index
Sword finger offer: the path with a certain value in the binary tree (backtracking)
Learning Android II from scratch - activity
What is the meaning of load balancing
Graduation project
[WinUI3]編寫一個仿Explorer文件管理器
Innovation training (V) configuration information
Unity3D 实用技巧 - 理论知识库(一)
Innovation training (IX) integration
Learning Android from scratch -- baseactivity and activitycollector
Customize the navigation bar at the top of wechat applet (adaptive wechat capsule button, flex layout)
Thoughts on a small program
Unity摄像头跟随鼠标旋转
信息学奥赛一本通 1955:【11NOIP普及组】瑞士轮 | OpenJudge 4.1 4363:瑞士轮 | 洛谷 P1309 [NOIP2011 普及组] 瑞士轮
【数据库】MySQL单表查询
Teach you how to build the ruoyi system by Tencent cloud
Pixel mobile phone brick rescue tutorial
Windows remote connection to redis
PHP 统计指定文件夹下文件的数量
Flink's important basics