php留言评论功能开发


php留言评论功能开发

文章插图
 

php留言评论功能开发

文章插图
发布留言界面

php留言评论功能开发

文章插图
查看留言界面
建立数据库创建表
//conn.php<?php $conn = MySQLi_connect("localhost", "root", "root") or die("数据库链接错误"); mysqli_select_db($conn,"bbs"); mysqli_query($conn, "set names utf8");?>
php留言评论功能开发

文章插图
数据库
创建发布留言界面
//add.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>留言页面</title>
<link rel="stylesheet" type="text/css" href=https://www.isolves.com/it/cxkf/yy/php/2019-09-06/"css.css">
<?php include ("add.php")?> //发布留言数据插入数据库
</head>
【php留言评论功能开发】<body>
<script>
function CheckPost() {
if(myform.user.value=https://www.isolves.com/it/cxkf/yy/php/2019-09-06/="")
{
alert("请填写用户");
myform.user.focus();
return false;
}
if (myform.title.value.length<5)
{
alert("标题不能少于5个字符");
myform.title.focus();
return false;
}
if (myform.content.value=https://www.isolves.com/it/cxkf/yy/php/2019-09-06/="")
{
alert("内容不能为空");
myform.content.focus();
return false;
}
}
</script>
<b> <a href=https://www.isolves.com/it/cxkf/yy/php/2019-09-06/"list.php">浏览留言
<hr size=1>
<form action="add.php" method="post" name="myform" onsubmit="return CheckPost();">
用户:<input type="text" size="10" name="user"/><br>
标题:<input type="text" name="title" /><br>
内容:<textarea name="content"></textarea><br>
<input type="submit" name="submit" value=https://www.isolves.com/it/cxkf/yy/php/2019-09-06/"发布留言" />
</form>
</body>
</html>
创建发布留言add.php页面
//add.php
<?php
include ("conn.php");
$id=$_POST['id'];
$user=$_POST['user'];
$title=$_POST['title'];
$content=$_POST['content'];
if($_POST['submit']){
$sql="insert into message(id,user,title,content,lastdate)values('','$user','$title','$content',now())";
mysqli_query($conn,$sql);
echo "<script>alert('提交成功!返回首页 。');location.href=https://www.isolves.com/it/cxkf/yy/php/2019-09-06/'add.html';";
}
?>
创建查看留言页面
//list.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>浏览留言</title>
<link rel="stylesheet" type="text/css" href=https://www.isolves.com/it/cxkf/yy/php/2019-09-06/"views/css.css">
<?php include ("conn.php"); ?>
</head>
<body>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef" >
<?php
$sql="select * from message order by id DESC"; //查询数据库
$query=mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($query)){ ?>
<tr bgcolor="#eff3ff">
<td><font color="red">标题:</font>
<?php echo $row['title'];?>
<font color="red">用户:</font>
<?php echo $row['user'];?>
<div align="right">
<a href=https://www.isolves.com/it/cxkf/yy/php/2019-09-06/"del.php?id=">删除
</div>
</td>
</tr>
<tr bgColor="#ffffff">
<td>发表内容:<?php echo $row['content'];?></td>


推荐阅读