当前位置:网站首页>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
边栏推荐
- Sword finger offer: symmetric binary tree (recursive iteration leetcode 101)
- The unity camera rotates with the mouse
- /etc/bash_ completion. D directory function (the user logs in and executes the script under the directory immediately)
- Leetcode009 -- search the target value in the array with binary search
- 泰克示波器DPO3054自校准SPC失败维修
- Simply drag objects to the item bar
- Spark small case - RDD, broadcast
- 2022/4/22
- AQS源码阅读
- redis和mysql区别
猜你喜欢
Druid -- JDBC tool class case
AQS源码阅读
Innovation training (V) configuration information
Download PDF from HowNet (I don't want to use CAJViewer anymore!!!)
[winui3] Écrivez une copie du gestionnaire de fichiers Explorer
Wechat payment function
解决ValueError: Argument must be a dense tensor: 0 - got shape [198602], but wanted [198602, 16].
/etc/bash_ completion. D directory function (the user logs in and executes the script under the directory immediately)
Learning Android II from scratch - activity
Unity RawImage背景无缝连接移动
随机推荐
【数据库】MySQL基本操作(基操~)
用LCR表完美测试无线充电系统中的线圈
La caméra Unity tourne avec la souris
Alibaba tip: it is better to create threads manually
负载均衡简介
Raspberry pie + opencv + opencv -- face detection ------- environment construction
解决ValueError: Argument must be a dense tensor: 0 - got shape [198602], but wanted [198602, 16].
Leetcode001 -- returns the subscript of the array element whose sum is target
Innovation training (VI) routing
leetcode004--罗马数字转整数
How can continuous integration (CI) / continuous delivery (CD) revolutionize automated testing
Sword finger offer: symmetric binary tree (recursive iteration leetcode 101)
CLion+OpenCV identify ID number - detect ID number
C list field sorting contains numbers and characters
View analysis of scenic spots in ArcGIS
Other problems encountered in debugging fingerprints
Graduation project
C# List字段排序含有数字和字符
Solve valueerror: argument must be a deny tensor: 0 - got shape [198602], but wanted [198602, 16]
leetcode001--返回和为target的数组元素的下标