html留言板代码精美

发布时间:2025-12-10 13:16:19 浏览次数:9

HTML留言板是网站常见的一个功能,它可以让网站上的用户在特定的页面上留下自己的意见和评论。今天我分享一个精美的HTML留言板代码,它不仅具有美观的外观,而且也很容易使用。

<!--留言板表单代码--><form name="commentform" method="post" action="comment.php"><!--用户输入姓名--><p><label for="name">Name:</label><input type="text" name="name"  required></p><!--用户输入邮箱--><p><label for="email">Email:</label><input type="email" name="email"  required></p><!--用户输入留言--><p><label for="comment">Comment:</label><textarea name="comment"  required></textarea></p><!--提交按钮--><p><input type="submit" name="submit" value="Submit"></p></form>
此留言板的外观设计简洁美观,注重用户体验。留言板分为三个输入框:姓名、邮箱和留言,用户填写后可以通过提交按钮将信息发送给网站管理员。
<!--留言展示区域--><p ><?php//连接数据库$dbconnect = mysqli_connect('localhost', 'username', 'password', 'database_name');//查询数据库中全部留言$commentquery = "SELECT * FROM comments ORDER BY comment_id DESC";$commentresult = mysqli_query($dbconnect, $commentquery);while ($row = mysqli_fetch_assoc($commentresult)) {//输出留言内容echo "<p><strong>" . $row['name'] . "</strong>  said:<br>";echo $row['comment'] . "</p>";}//关闭连接mysqli_close($dbconnect);?></p>
此代码通过PHP连接数据库,将数据库中已有的留言查询出来并展示在网站上。可以看到,留言框的外观也是通过CSS样式文件设置的。此留言板的表单、展示区、PHP连接数据库代码都非常简洁明了,容易上手。相信使用这一份代码,你也可以为你的网站添加美观而又高效的留言板功能。

需要做网站?需要网络推广?欢迎咨询客户经理 13272073477