PHP+mysql+jquery构建留言板聊天室-留言的增、删、改功能

本项目所有代码都存储在github上有需要的可以去github上下载,希望大家给个 Satr
项目文章目录:
1、PHP+mysql+jquery构建留言板加聊天室-连接数据库
2、PHP+mysql+jquery构建留言板加聊天室-用户注册(带用户头像上传)
3、PHP+mysql+jquery构建留言板加聊天室-用户登录
4、PHP+mysql+jquery构建留言板加聊天室-留言展示
5、PHP+mysql+jquery构建留言板聊天室-留言的增、删、改功能
本文实现了留言的增、删、改功能:

留言的添加:

add.php

?php
require_once('./conf.php');
?>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>添加留言</title>
    <link href="css/logindo.css" type="text/css" rel="stylesheet"> 
</head>
<body>
<div class="main">
    <h2>添加留言</h2>
    <form action="./addto.php" method="post" enctype="multipart/form-data">
    <table class="table-integral">
        <tbody id="content_page">
            <tr>
                <td>标题</td>
                <td><input type="text" name="title"></td>
            </tr>
            <tr>
                <td>内容</td>
                <td><input type="text" name="content"></td>
            </tr>
            <tr>
                <td colspan="2"><input type="submit" name="提交"></td>

            </tr>
            
            
        </tbody>
    </table>
    </form>
</div><!--main-->
</body>
</html>


addto.php

<?php
require_once('./conf.php');
if (!$title = $_POST['title']) {
    echo '
        <script language="javascript" type="text/javascript">
            alert("请输入留言标题!");
            window.location.href="./add.php"; 
        </script>';
    exit;
}
if (!$content = $_POST['content']) {
    echo '
        <script language="javascript" type="text/javascript">
            alert("请输入留言内容!");
            window.location.href="./add.php"; 
        </script>';
    exit;
}
$contents = $mysql->query("select * from ly_user where username=".$_SESSION['username']."");#查询返回一个对象
$row = $contents->fetch_array(MYSQLI_ASSOC);#把查询回来的对象值变成数组,并以字段作为健
//$row = mysqli_fetch_array($contents);
$contents=$row['headimg'];#获取到头像的地址
$sql = "insert into ly_content (usernameid, headimg,title, content, time) values (".$_SESSION['username'].",'".$contents."','".$title."', '".$content."', '".time()."')";
$result = $mysql->insert($sql);#调用mysql里的 方法
//$db=mysqli_connect('127.0.0.1','root','root','test2');
//$username=$_SESSION['username'];

//$sqll="select headimg from ly_user where username=".$_SESSION['username']."";
//$r=mysqli_query($db,$sqll);
//$row = mysqli_fetch_array($r);
//$headimg=$row['headimg']; 
//留言成功,更新用户头像地址到guestbook表中
//$t = $mysql->updata('update ly_content set headimg="'.$headimg.'" where username="'.$username.'"');
if ($result) {
    echo '
        <script language="javascript" type="text/javascript">
            alert("留言成功!");
            window.location.href="./show.php"; 
        </script>';
    exit;
} else {//弹出错误码和错误信息
    echo '
        <script language="javascript" type="text/javascript">
            alert("留言失败,错误代码:'.$mysql->err['code'].',错误为:'.$mysql_err['msg'].'!");  
            window.location.href="./add.php"; 
        </script>';
    exit;
}
?>

留言的修改

up.php

<?php
require_once('./conf.php');

?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>

	<?php 
	$id=$_GET['id'];
  $sql="select * from ly_content where id=".$id." ";//找出对应id的信息内容
$contents = $mysql->query($sql);#查询返回一个对象
$row = $contents->fetch_array(MYSQLI_ASSOC);#把查询回来的对象值变成数组,并以字段作为健
	?>
  
	<form action="up_do.php" method="post" >
		<input type="hidden" name="xg" value="<?php echo $row['id']; ?>"/>
	<table align="center" width="441" border="1">
  <tbody>
    <tr>
		<td height="30" colspan="2" align="center">编辑留言</td>
    </tr>
    <tr>
      <td width="74px" height="74">留言内容</td>
      <td width="355px"><textarea name="content" style="width:355px;height:70px;"><?php echo $row['content'];?></textarea></td>
    </tr>
    <tr>
     <td colspan="2"><div align="center">
      <input type="submit" value="确认修改" >
      </div></td>
    </tr>
  </tbody>
</table>
</form>
</body>
</html>

up_do.php

<?php
require_once('./conf.php');
?>
	<?php 
     $id =$_POST['xg'];#获取当前用户id
	 $content=$_POST['content'];#获取用户修改后的留言
	 $sql =" update ly_content set content ='".$content."' where id='".$id."' ";
	 $result = $mysql->updata($sql);#调用成员函数执行updata修改操作
	// $rs=mysqli_query($db,$sql);
	 if($result){
		 exit('<script>alert("编辑成功");window.location.href ="show.php"</script>)');}else{
			 exit('<script>alert("编辑失败");history.back();</script>');
			 }
?>		

留言删除

del.php

<?php
require_once('./conf.php');
if (!$id = $_GET['id']) {
   echo '
        <script language="javascript" type="text/javascript">
            alert("参数错误!");
            window.location.href="./show.php"; 
        </script>';
    exit;
}
//echo "delete from ly_content where id=$id";die;
$result = $mysql->deldata("delete from ly_content where id=$id");
if ($result) {
    echo '
        <script language="javascript" type="text/javascript">
            alert("删除成功!");
            window.location.href="./show.php"; 
        </script>';
    exit;
} else {
   echo '
        <script language="javascript" type="text/javascript">
            alert("删除失败,错误代码:'.$mysql->err['code'].',错误为:'.$mysql_err['msg'].'!");
            window.location.href="./show.php"; 
        </script>';
    exit;
}
?>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值