实现功能:
- 用户登录
- 用户注册
- 用户添加留言:可选择留言分类(建议、反馈、投诉)
- 用户查看留言:可根据上述分类对留言信息进行筛选
- 留言翻页:每页显示10条
- 留言编辑:可以编辑自己的留言信息
- 留言删除:可以删除自己的留言信息
注册:(register.php)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="utf-8"> 5 <title>particles.js</title> 6 <meta name="description" content="particles.js is a lightweight JavaScript library for creating particles."> 7 <meta name="author" content="Vincent Garreau" /> 8 <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> 9 <link rel="stylesheet" media="screen" href="demo/css/style.css"> 10 <style type="text/css"> 11 </style> 12 </head> 13 <body> 14 15 <!-- count particles --> 16 <div class="count-particles"> 17 <span class="js-count-particles">--</span> particles 18 </div> 19 <!-- <div id="particles-js" style="position: absolute;top: 0; 100%;"></div> --> 20 <!-- particles.js container --> 21 <div id="particles-js" style="position: absolute;top: 0; 100%; background-color: #000" align="center"> 22 <table width="360px" border="1" align="center" style="background: url(素材/回形针.png); z-index: -1" > 23 <form method="post" action="reg_do.php" enctype="multipart/form-data"> 24 <tr> 25 <td align="center" colspan="2" style="font-size: 36px">用户注册</td> 26 </tr> 27 <tr> 28 <td>用户名:</td> 29 <td><input type="text" name="username" id="username"></td> 30 </tr> 31 <tr> 32 <td>用户昵称:</td> 33 <td><input type="text" name="nickname" id="nickname"></td> 34 </tr> 35 <tr> 36 <td>用户密码:</td> 37 <td><input type="password" name="password" id="password"></td> 38 </tr> 39 <tr> 40 <td>重复密码:</td> 41 <td><input type="password" name="repeatpassword" id="repeatpassword"></td> 42 </tr> 43 <tr> 44 <td>用户头像:</td> 45 <td> 46 <!-- <input type="hidden" name="MAX_FILE_SIZE" value="1024"> --> 47 <input type="file" name="profile" id="profile" > 48 </td> 49 </tr> 50 <tr> 51 <td colspan="2" align="center"><input type="submit" name="register" id="register"></td> 52 </tr> 53 </form> 54 </table> 55 </div> 56 <!-- scripts --> 57 <script src="particles.js"></script> 58 <script src="demo/js/app.js"></script> 59 60 <!-- stats.js --> 61 <script src="demo/js/lib/stats.js"></script> 62 <script src="https://cdn.bootcss.com/jquery/1.12.2/jquery.js"></script> 63 <script> 64 var count_particles, stats, update; 65 stats = new Stats; 66 stats.setMode(0); 67 stats.domElement.style.position = 'absolute'; 68 stats.domElement.style.left = '0px'; 69 stats.domElement.style.top = '0px'; 70 document.body.appendChild(stats.domElement); 71 count_particles = document.querySelector('.js-count-particles'); 72 update = function() { 73 stats.begin(); 74 stats.end(); 75 if (window.pJSDom[0].pJS.particles && window.pJSDom[0].pJS.particles.array) { 76 count_particles.innerText = window.pJSDom[0].pJS.particles.array.length; 77 } 78 requestAnimationFrame(update); 79 }; 80 requestAnimationFrame(update); 81 82 83 </script> 84 85 </body> 86 </html>
我这里加入了particles-js的粒子特效,效果如下(用table做这个有bug,以后还是不用table+form了)
是有动态效果的,很炫酷,由于动态图可能有bug,这里我上传的.png
贯穿全剧的Config(配置)文件:
1 <?php 2 $db = mysqli_connect('127.0.0.1', 'root', 'password', 'guestattrs'); 3 session_start(); 4 include 'lab/Uploads.php'; 5 $upload_dir = 'uploads/' 6 ?>
注册对应的判断注册输入信息是否合法,合法就入库(reg_do.php)
1 <?php include_once('config.php') ?> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title></title> 6 </head> 7 <body> 8 <?php 9 $username = $_POST['username']; 10 $nickname = $_POST['nickname']; 11 $password = $_POST['password']; 12 $repeatpassword = $_POST['repeatpassword']; 13 14 if (!$username) 15 { 16 exit('<script>alert("请填写用户名! ") 17 history.back();</script>'); 18 } 19 if (!$nickname) 20 { 21 exit('<script>alert("请填写用户昵称! ") 22 history.back();</script>'); 23 } 24 if (!$password) 25 { 26 exit('<script>alert("请填写密码! ") 27 history.back();</script>'); 28 } 29 if (!$repeatpassword) 30 { 31 exit('<script>alert("请填写重复密码! ") 32 history.back();</script>'); 33 } 34 //同时判断其他的参数是否填写 35 36 //判断该用户名是否存在 37 $sql = "select * from userlist where username = '" . $username . "' "; 38 $query = mysqli_query($db, $sql); 39 if (!$query) 40 { 41 exit('SQL语句执行错误:1 ' . mysqli_error($db)); 42 } 43 if ($info = mysqli_fetch_array($query)) 44 { 45 exit('<script>alert("该用户名已存在, 请重新填写!");history.back();</script>'); 46 } 47 48 //判断密码是否一致 49 if ($password != $repeatpassword) 50 { 51 die('<script>alert("两次填写密码不一致,请重写填写");history.back()</script>'); 52 } 53 54 #deal with profile 55 $profile = $_FILES['profile']; 56 $upload = new Uploads($profile, $upload_dir, array('.png', '.jpg', '.gif'), 2 * 1024 * 1024 * 8);//2M 57 $returnInfo = $upload->uploadFile(); 58 $newfilename = $upload->newfiledir; 59 print_r($returnInfo); 60 if ($returnInfo['status'] == 0) 61 die($returnInfo['msg']); 62 // $error = $profile['error']; 63 // switch ($error) { 64 // case 0: 65 // #$profileName = $profile['name']; 66 // #echo "您的个人相片为: ". $profileName. "<br/>"; 67 // $profileTemp = $profile['tmp_name']; 68 // $ext = substr($profile['name'], strrpos($profile['name'], '.')); 69 // $newfilename = date('YMDHis'). rand(1000, 9999) . $ext; 70 // $destination = "Picture/"; 71 // $filedir = $destination . date('Y') . '/' . date('m') . '/'; 72 // if (!is_dir($filedir)) 73 // { 74 // $dirs = explode('/', trim($filedir, '/')); 75 // print_r($dirs); 76 // $newdir = ''; 77 // foreach($dirs as $v) 78 // { 79 // $newdir = $newdir . $v . '/'; 80 // if (!is_dir($newdir)) 81 // { 82 // mkdir($newdir); 83 // } 84 // } 85 // } 86 // $newfilename = $filedir . $newfilename; 87 // move_uploaded_file($profileTemp, $newfilename); 88 // //echo "文件上传成功!<br/>"; 89 // break; 90 // case 1: 91 // echo "上传的头像超过了php.ini中upload_max_filesize选项限制的值!<br/>"; 92 // break; 93 // case 2: 94 // echo "上传文件的头像超过了FORM表单MAX_FILE_SIZE选项指定的值!<br/>"; 95 // break; 96 // case 3: 97 // echo "文件只有部分被上传!<br/>"; 98 // break; 99 // case 4: 100 // echo "没有选择上传文件!<br/>"; 101 // break; 102 // } 103 104 //执行注册 105 $sql = "insert into userlist(username, nickname, password, regtime, regip, headimg) values('" . $username . "', '". $nickname . "', '". md5($password) . 106 "'," . time() . ",'" . $_SERVER['REMOTE_ADDR'] . "','" . $newfilename . "')"; 107 $query = mysqli_query($db, $sql); 108 if (!$query) 109 { 110 exit('SQL语句执行错误:' . mysqli_error($db)); 111 } 112 else 113 { 114 exit('<script>alert("注册成功,请登录");window.location.href = "sign_in.php"</script>'); 115 } 116 ?> 117 </body> 118 </html>
登录:
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>用户登录</title> 6 </head> 7 <body background="素材/方格.jpg" style=" background-repeat: no-repeat; background-size: 100% 100%; background-attachment: fixed;"> 8 <table width="360px" border="1" align="center"> 9 <form method="post" action="sign_do.php"> 10 <tr> 11 <td align="center" colspan="2" style="font-size: 36px">用户登录</td> 12 </tr> 13 <tr> 14 <td>用户名:</td> 15 <td><input type="text" name="username" id="username"></td> 16 </tr> 17 <tr> 18 <td>用户密码:</td> 19 <td><input type="password" name="password" id="password"></td> 20 </tr> 21 <tr> 22 <td colspan="2" align="center"><input type="submit" name="register" id="register">如果您没有账号,请<a href="register.php">注册</a></td> 23 </tr> 24 </form> 25 </table> 26 </body> 27 </html>
登录信息是否正确判断,正确则进入聊天室
1 <?php include_once('config.php') ?> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title></title> 6 </head> 7 <body> 8 <?php 9 $username = $_POST['username']; 10 $password = $_POST['password']; 11 if (!$username) 12 { 13 exit('<script>alert("请填写用户名! ") 14 history.back();</script>'); 15 } 16 if (!$password) 17 { 18 exit('<script>alert("请填写密码! ") 19 history.back();</script>'); 20 } 21 22 //若用户名正确,判断密码是否正确 23 $sql = "select * from userlist where username = '" . $username ."' and password = '" . md5($password) . "' "; 24 $query = mysqli_query($db, $sql); 25 if (!$query) 26 { 27 exit('SQL语句执行错误: ' . mysqli_error($db)); 28 } 29 if (!$info = mysqli_fetch_array($query)) 30 { 31 exit('<script>alert("密码不正确, 请重新填写!");history.back();</script>'); 32 } 33 34 $_SESSION['uid'] = $info['uid']; 35 $_SESSION['nickname'] = $info['nickname']; 36 die('<script>alert("登录成功");window.location.href="chat.php"</script>') 37 ?> 38 </body> 39 </html>
聊天室(留言分为了三类,建议,反馈,投诉,三类分别有对应的php后台处理)
注:由于是后面才加的分类,所以对没有修改以前直接提交的form表单
先是判断是否登录:
1 <?php 2 if (!$_SESSION['uid']) 3 { 4 die('<script>alert("未登录,请登录");window.location.href = "sign_in.php";</script>'); 5 } 6 ?>
聊天室:
1 <?php 2 include_once('config.php'); 3 include_once('if_register.php'); 4 ?> 5 <!DOCTYPE html> 6 <html lang="en"> 7 <head> 8 <title></title> 9 10 <!-- <meta charset="utf-8"> 11 <title>particles.js</title> 12 <meta name="description" content="particles.js is a lightweight JavaScript library for creating particles."> 13 <meta name="author" content="Vincent Garreau" /> 14 <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> 15 <link rel="stylesheet" media="screen" href="demo/css/style.css"> --> 16 </head> 17 </head> 18 <body background="素材/回形针.png" style=" background-repeat:no-repeat; background-size:100% 100%; background-attachment: fixed;" > 19 20 <?php 21 $name = $_SESSION['nickname']; 22 $sql = "select headimg from userlist where nickname = '" . $name ."' "; 23 $query = mysqli_query($db, $sql); 24 if (!$query) 25 die ('sql语句执行错误'. mysqli_error($db)); 26 else 27 $info = mysqli_fetch_array($query); 28 // print_r($info); 29 // print_r($info['headimg']); 30 ?> 31 <p style="font-size: 10px; color: #3F5D7D;"> 32 <?php echo "欢迎您,亲爱的" . $name; ?> 33 <img src="<?php echo $info['headimg']; ?>" style=" 50px; height: 50px; " /> 34 <a href="signout.php">注销</a> 35 </p> 36 <br/> 37 <table width="1000px" border="1" align="center"> 38 <form method="post" action="record.php"> 39 <tr> 40 <td colspan="3" align="center" style="font-size: 36px; background-color: rgb(#f3456d);"> 41 添加留言 <img src="素材/noun_1580348_cc.png" style=" 50px; height: 50px; "> </td> 42 </tr> 43 <tr> 44 <td colspan="2" align="center" style="font-size: 20px; color: #008AB8;">留言:</td> 45 <!-- <td><textarea rows="10" cols="40" name="record"></textarea></td> --> 46 <td> 47 <a href="suggest.php">建议</a> 48 <a href="feedback.php">反馈</a> 49 <a href="complaint.php">投诉</a> 50 </td> 51 </tr> 52 <tr> 53 <td colspan="2"></td> 54 <td><input type="submit" name="chat"></td> 55 <tr> 56 <td colspan="3" align="center"> 57 您想查看什么: 58 <a href="chat.php?comment_type=chat">建议</a> 59 <a href="chat.php?comment_type=feedback">反馈</a> 60 <a href="chat.php?comment_type=complaint">投诉</a> 61 </td> 62 </tr> 63 </tr> 64 <!-- 打印留言 --> 65 <?php 66 if (isset($_GET['comment_type'])) 67 $comment_type = $_GET['comment_type']; 68 else 69 $comment_type = 'chat'; 70 71 if (isset($_GET['page'])) 72 { 73 $page = $_GET['page']; 74 $page_start = ($page - 1) * 10; 75 } 76 else 77 { 78 $page = 1; 79 $page_start = 0; 80 } 81 82 // print_r($_SERVER['QUERY_STRING']); 83 $parameters = $_GET; 84 $url = $comment_type . '.php?'; 85 foreach ($parameters as $key => $value) 86 { 87 if ($key != 'page') 88 $url .= $key . '=' . $value . '&'; 89 } 90 $url .= 'page='; 91 92 // 评论的总条数 93 $total_chat = 0; 94 $sql = "select $comment_type.*, userlist.nickname, userlist.headimg 95 from $comment_type left join userlist on $comment_type.uid = userlist.uid";// limit 1 96 $query = mysqli_query($db, $sql); 97 if (!$query) 98 die ('sql语句执行错误'. mysqli_error($db)); 99 while ($info = mysqli_fetch_array($query)) 100 $total_chat++; 101 102 $sql = "select $comment_type.*, userlist.nickname, userlist.headimg 103 from $comment_type left join userlist on $comment_type.uid = userlist.uid 104 order by $comment_type.addtime desc limit " . $page_start . ", 10";// limit 1 105 $query = mysqli_query($db, $sql); 106 if (!$query) 107 die ('sql语句执行错误'. mysqli_error($db)); 108 while ($info = mysqli_fetch_array($query)) 109 { 110 // print_r($info); 111 // echo "<br/>;"; 112 // $sql = "select username from userlist where uid = '" . $info['uid'] . "'"; 113 // $query2 = mysqli_query($db, $sql); 114 // if (!$query2) 115 // die ('sql语句执行错误'. mysqli_error($db)); 116 // $info2 = mysqli_fetch_array($query2); 117 ?> 118 <tr> 119 <td style="text-align: center;"> 120 <img align="center" src="<?php echo $info['headimg']; ?>" 121 style=" 50px; height: 50px;" /> 122 <!-- <br/> --> 123 <?php echo $info['nickname']; ?> say: 124 </td> 125 <td align="center" style="font-size: 36px;"> 126 <?php echo $info['comment']; ?> 127 </td> 128 <td> 129 <p> 130 <?php 131 echo date("Y年m月d日h小时i分钟s秒", $info['addtime']); 132 // echo strtotime(date("Ymdhis", $info['addtime'])); 133 ?> 134 <?php 135 print_r($_SESSION['uid']); 136 if ($_SESSION['uid'] == $info['uid']) 137 { 138 ?> 139 <br> 140 <a href="comment_edit.php?id=<?php echo $info['id']; ?>">编辑</a> 141 <a href="comment_delete.php?id=<?php echo $info['id']; ?>">删除</a> 142 <?php 143 } 144 ?> 145 </p> 146 </td> 147 </tr> 148 <?php 149 } 150 ?> 151 </form> 152 </table> 153 <?php 154 //查询评论的总条数 155 // $sql = "select count(*) from chat"; 156 // $total_chat = mysqli_query($db, $sql); 157 // // print_r($total_chat); 158 // $count = mysqli_fetch_array($total_chat); 159 // print_r($count); 160 161 // print_r($total_chat / 10); 162 // if (!$total_chat) 163 // die('sql语句执行错误' . mysqli_error($db)); 164 ?> 165 <li class="list"> 166 <a href= 167 <?php 168 if ($page > 1) 169 echo $url . ($page - 1); 170 else 171 echo $url . $page; 172 ?> 173 >上一页</a> 174 <?php 175 $offset = 1; 176 $total_page = ceil($total_chat / 10); 177 for ($i = $page - $offset; $i <= $page + $offset; $i++) 178 { 179 if ($i != $page && $i > 0 && $i <= $total_page) 180 { 181 ?> 182 <a href= <?php echo $url . $i; ?> > <?php echo $i;?> </a> 183 <?php 184 } 185 else if ($i == $page) 186 { 187 ?> 188 <?php echo $page;?> 189 <?php 190 } 191 } 192 ?> 193 <a href= 194 <?php 195 if ($page < $total_page) 196 echo $url . ($page + 1); 197 else 198 echo $url . $page; 199 ?> 200 >下一页</a> 201 <a href= <?php echo $url . $total_page;?> >尾页</a> 202 </li> 203 204 205 206 207 </div> 208 </body> 209 </html>
对Suggest(建议)的处理(分成两层,先进入建议的留言页面,然后第二层进行入库处理):
1 <?php 2 include_once('config.php'); 3 include_once('if_register.php'); 4 ?> 5 <!DOCTYPE html> 6 <html> 7 <head> 8 <style type="text/css"> 9 10 </style> 11 <title></title> 12 </head> 13 <body background="素材/回形针.png" style=" background-repeat:no-repeat; background-size:100% 100%; background-attachment: fixed;" > 14 <?php 15 $name = $_SESSION['nickname']; 16 ?> 17 <p style="font-size: 10px; color: #3F5D7D;"> 18 <?php echo "欢迎您,亲爱的" . $name; ?> 19 <a href="signout.php">注销</a> 20 <?php 21 ?> 22 </p> 23 <br/> 24 <table width="1000px" border="1" align="center"> 25 <form method="post" action="suggest_do.php"> 26 <tr> 27 <td colspan="3" align="center" style="font-size: 36px; background-color: rgb(#f3456d);"> 28 添加建议 <img src="素材/noun_1580348_cc.png" style=" 50px; height: 50px; "> </td> 29 </tr> 30 <tr> 31 <td colspan="2" align="center" style="font-size: 20px; color: #008AB8;">建议 :</td> 32 <td><textarea rows="10" cols="40" name="comment"></textarea></td> 33 </tr> 34 <tr> 35 <td colspan="2"></td> 36 <td> 37 <input type="submit" name="chat" id="submit" value="提交"> 38 </td> 39 </tr> 40 </body> 41 </html>
1 <?php 2 include_once('config.php'); 3 include_once('if_register.php'); 4 ?> 5 <!DOCTYPE html> 6 <html> 7 <head> 8 <title></title> 9 </head> 10 <body> 11 <?php 12 $comment = $_POST['comment']; 13 $uid = $_SESSION['uid']; 14 $addtime = time(); 15 $active = 0; 16 $ip = $_SERVER['REMOTE_ADDR']; 17 if (!$comment) 18 { 19 die('<script>alert("建议不能为空"); history.back();</script>'); 20 } 21 $sql = "insert into chat(comment, uid, addtime, active, ip) values ('" . $comment . "','" . $uid . "','" . $addtime . "','" . $active . "','" . $ip . "')"; 22 $query = mysqli_query($db, $sql); 23 if (!$query) 24 { 25 die('SQL语句执行错误'. mysqli_error($db)); 26 } 27 else 28 { 29 die('<script>alert("建议成功");window.location.href = "chat.php"</script>'); 30 } 31 ?> 32 </body> 33 </html>
对FeedBack(反馈)的处理(分成两层,先进入反馈的留言页面,然后第二层进行入库处理):
1 <?php 2 include_once('config.php'); 3 include_once('if_register.php'); 4 ?> 5 <!DOCTYPE html> 6 <html> 7 <head> 8 <style type="text/css"> 9 10 </style> 11 <title></title> 12 </head> 13 <body background="素材/回形针.png" style=" background-repeat:no-repeat; background-size:100% 100%; background-attachment: fixed;" > 14 <?php 15 $name = $_SESSION['nickname']; 16 ?> 17 <p style="font-size: 10px; color: #3F5D7D;"> 18 <?php echo "欢迎您,亲爱的" . $name; ?> 19 <a href="signout.php">注销</a> 20 <?php 21 ?> 22 </p> 23 <br/> 24 <table width="1000px" border="1" align="center"> 25 <form method="post" action="feedback_do.php"> 26 <tr> 27 <td colspan="3" align="center" style="font-size: 36px; background-color: rgb(#f3456d);"> 28 添加反馈 <img src="素材/noun_1580348_cc.png" style=" 50px; height: 50px; "> </td> 29 </tr> 30 <tr> 31 <td colspan="2" align="center" style="font-size: 20px; color: #008AB8;">反馈 :</td> 32 <td><textarea rows="10" cols="40" name="comment"></textarea></td> 33 </tr> 34 <tr> 35 <td colspan="2"></td> 36 <td> 37 <input type="submit" name="chat" id="submit" value="提交"> 38 </td> 39 </tr> 40 </body> 41 </html>
1 <?php 2 include_once('config.php'); 3 include_once('if_register.php'); 4 ?> 5 <!DOCTYPE html> 6 <html> 7 <head> 8 <title></title> 9 </head> 10 <body> 11 <?php 12 $comment = $_POST['comment']; 13 $uid = $_SESSION['uid']; 14 $addtime = time(); 15 $active = 0; 16 $ip = $_SERVER['REMOTE_ADDR']; 17 if (!$comment) 18 { 19 die('<script>alert("反馈不能为空"); history.back();</script>'); 20 } 21 $sql = "insert into feedback(comment, uid, addtime, active, ip) values ('" . $comment . "','" . $uid . "','" . $addtime . "','" . $active . "','" . $ip . "')"; 22 $query = mysqli_query($db, $sql); 23 if (!$query) 24 { 25 die('SQL语句执行错误'. mysqli_error($db)); 26 } 27 else 28 { 29 die('<script>alert("反馈成功");window.location.href = "chat.php"</script>'); 30 } 31 ?> 32 </body> 33 </html>
对Complaint(投诉)的处理(分成两层,先进入投诉的留言页面,然后第二层进行入库处理):
1 <?php 2 include_once('config.php'); 3 include_once('if_register.php'); 4 ?> 5 <!DOCTYPE html> 6 <html> 7 <head> 8 <style type="text/css"> 9 10 </style> 11 <title></title> 12 </head> 13 <body background="素材/回形针.png" style=" background-repeat:no-repeat; background-size:100% 100%; background-attachment: fixed;" > 14 <?php 15 $name = $_SESSION['nickname']; 16 ?> 17 <p style="font-size: 10px; color: #3F5D7D;"> 18 <?php echo "欢迎您,亲爱的" . $name; ?> 19 <a href="signout.php">注销</a> 20 <?php 21 ?> 22 </p> 23 <br/> 24 <table width="1000px" border="1" align="center"> 25 <form method="post" action="complaint_do.php"> 26 <tr> 27 <td colspan="3" align="center" style="font-size: 36px; background-color: rgb(#f3456d);"> 28 添加投诉 <img src="素材/noun_1580348_cc.png" style=" 50px; height: 50px; "> </td> 29 </tr> 30 <tr> 31 <td colspan="2" align="center" style="font-size: 20px; color: #008AB8;">投诉 :</td> 32 <td><textarea rows="10" cols="40" name="comment"></textarea></td> 33 </tr> 34 <tr> 35 <td colspan="2"></td> 36 <td> 37 <input type="submit" name="chat" id="submit" value="提交"> 38 </td> 39 </tr> 40 </body> 41 </html>
1 <?php 2 include_once('config.php'); 3 include_once('if_register.php'); 4 ?> 5 <!DOCTYPE html> 6 <html> 7 <head> 8 <title></title> 9 </head> 10 <body> 11 <?php 12 $comment = $_POST['comment']; 13 $uid = $_SESSION['uid']; 14 $addtime = time(); 15 $active = 0; 16 $ip = $_SERVER['REMOTE_ADDR']; 17 if (!$comment) 18 { 19 die('<script>alert("投诉不能为空"); history.back();</script>'); 20 } 21 $sql = "insert into complaint(comment, uid, addtime, active, ip) values ('" . $comment . "','" . $uid . "','" . $addtime . "','" . $active . "','" . $ip . "')"; 22 $query = mysqli_query($db, $sql); 23 if (!$query) 24 { 25 die('SQL语句执行错误'. mysqli_error($db)); 26 } 27 else 28 { 29 die('<script>alert("投诉成功");window.location.href = "chat.php"</script>'); 30 } 31 ?> 32 </body> 33 </html>
编辑留言:
1 <?php 2 include_once('config.php'); 3 include_once('if_register.php'); 4 ?> 5 <!DOCTYPE html> 6 <html> 7 <head> 8 <style type="text/css"> 9 10 </style> 11 <title></title> 12 </head> 13 <body background="素材/回形针.png" style=" background-repeat:no-repeat; background-size:100% 100%; background-attachment: fixed;" > 14 <?php 15 $name = $_SESSION['nickname']; 16 $sql = "select headimg from userlist where nickname = '" . $name ."' "; 17 $query = mysqli_query($db, $sql); 18 if (!$query) 19 die ('sql语句执行错误'. mysqli_error($db)); 20 else 21 $info = mysqli_fetch_array($query); 22 // print_r($info); 23 // print_r($info['headimg']); 24 ?> 25 <p style="font-size: 10px; color: #3F5D7D;"> 26 <?php echo "欢迎您,亲爱的" . $name; ?> 27 <img src="<?php echo $info['headimg']; ?>" style=" 50px; height: 50px; " /> 28 <a href="signout.php">注销</a> 29 <?php 30 $id = intval($_GET['id']); 31 //判断id是否是正确的 32 if ($id <= 0) 33 die('<script>alert("参数错误");history.back();</script>'); 34 //判断id是否是当前登录用户的:根据id号和登陆者的会话uid进行判断 35 $sql = "select * from chat where id = " . $id . " and uid = " . $_SESSION['uid']; 36 //将查询出来的信息放到comment的值里面 37 $query = mysqli_query($db, $sql); 38 if (!$query) 39 die ('sql语句执行错误'. mysqli_error($db)); 40 $info = mysqli_fetch_array($query); 41 if (!$info) 42 { 43 die('<script>alert("参数错误");history.back();</script>'); 44 } 45 ?> 46 </p> 47 <br/> 48 <table width="1000px" border="1" align="center"> 49 <form method="post" action="comment_edit_do.php"> 50 <tr> 51 <td colspan="3" align="center" style="font-size: 36px; background-color: rgb(#f3456d);"> 52 添加留言 <img src="素材/noun_1580348_cc.png" style=" 50px; height: 50px; "> </td> 53 </tr> 54 <tr> 55 <td colspan="2" align="center" style="font-size: 20px; color: #008AB8;">留言:</td> 56 <td><textarea rows="10" cols="40" name="comment"><?php echo $info['comment'];?></textarea></td> 57 </tr> 58 <tr> 59 <td colspan="2"></td> 60 <td> 61 <input type="submit" name="chat" id="submit" value="提交"> 62 <input type="hidden" name="id" value="<?php echo $info['id']; ?>"> 63 </td> 64 </tr> 65 </body> 66 </html>
1 <?php 2 include_once('config.php'); 3 include_once('if_register.php'); 4 ?> 5 <!DOCTYPE html> 6 <html> 7 <head> 8 <title></title> 9 </head> 10 <body> 11 <?php 12 $id = intval($_POST['id']); 13 $comment = $_POST['comment']; 14 // 判断参数是否正确 15 if ($id <= 0) 16 die('<script>alert("参数错误");history.back();</script>'); 17 // 执行编辑SQL语句 18 $sql = "update chat set comment = '" . $comment . "' where uid = " . $_SESSION['uid'] . " and id = " . $id; 19 //执行SQL语句 20 $query = mysqli_query($db, $sql); 21 if (!$query) 22 die ('sql语句执行错误'. mysqli_error($db)); 23 //判断是否成功,根据结果跳转页面 24 die('<script>alert("修改成功");window.location.href = "chat.php";</script>'); 25 ?> 26 </body> 27 </html>
删除留言:
1 <?php 2 include_once('config.php'); 3 include_once('if_register.php'); 4 ?> 5 <!DOCTYPE html> 6 <html> 7 <head> 8 <title></title> 9 </head> 10 <body> 11 <?php 12 $id = intval($_GET['id']); 13 // 判断参数是否正确 14 if ($id <= 0) 15 die('<script>alert("参数错误");history.back();</script>'); 16 // 执行删除SQL语句 17 $sql = "delete from chat where uid = " . $_SESSION['uid'] . " and id = " . $id; 18 //执行SQL语句 19 $query = mysqli_query($db, $sql); 20 if (!$query) 21 die ('sql语句执行错误'. mysqli_error($db)); 22 //判断是否成功,根据结果跳转页面 23 die('<script>alert("删除成功");window.location.href = "chat.php";</script>'); 24 ?> 25 </body> 26 </html>