当前位置:网站首页>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
边栏推荐
- 2022/4/22
- View analysis of scenic spots in ArcGIS
- Learning Android V from scratch - UI
- Spell it! Two A-level universities and six B-level universities have abolished master's degree programs in software engineering!
- 用LCR表完美测试无线充电系统中的线圈
- Custom switch control
- Innovation training (XI) airline ticket crawling company information
- General enumeration constant class
- Jetpack -- lifecycle usage and source code analysis
- MySQL - data read / write separation, multi instance
猜你喜欢
【数据库】表的查看、修改和删除
跨境电商 | Facebook 和 Instagram:哪个社交媒体更适合你?
Download PDF from HowNet (I don't want to use CAJViewer anymore!!!)
Opencv + clion face recognition + face model training
PIP3 installation requests Library - the most complete pit sorting
Innovative practice of short video content understanding and generation technology in meituan
Sword finger offer: the path with a certain value in the binary tree (backtracking)
Innovation training (IV) preliminary preparation - server
/etc/bash_ completion. D directory function (the user logs in and executes the script under the directory immediately)
Record the ThreadPoolExecutor main thread waiting for sub threads
随机推荐
【数据库】MySQL单表查询
Use model load_ state_ Attributeerror appears when dict(): 'STR' object has no attribute 'copy‘
Teach you how to build the ruoyi system by Tencent cloud
Pixel mobile phone brick rescue tutorial
[2021] Spatio-Temporal Graph Contrastive Learning
【数据库】MySQL基本操作(基操~)
Programmers complain: I really can't live with a salary of 12000. Netizen: how can I say 3000
js 判断数字字符串中是否含有字符
Gets all dates between two times
Eight misunderstandings that should be avoided in data visualization
Unity3D 实用技巧 - 理论知识库(一)
Open the past and let's start over.
Excel protects worksheets and workbooks from damage
The object needs to add additional attributes. There is no need to add attributes in the entity. The required information is returned
跨境电商 | Facebook 和 Instagram:哪个社交媒体更适合你?
Innovation training (VII) FBV view & CBV view
Unity摄像头跟随鼠标旋转
Unity攝像頭跟隨鼠標旋轉
[2022 ICLR] Pyraformer: Low-Complexity Pyramidal Attention for Long-Range 时空序列建模和预测
Details related to fingerprint payment