實現功能:php
註冊:(register.php)css
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;width: 100%;"></div> --> 20 <!-- particles.js container --> 21 <div id="particles-js" style="position: absolute;top: 0;width: 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了)html
是有動態效果的,很炫酷,因爲動態圖可能有bug,這裏我上傳的.pngmysql
貫穿全劇的Config(配置)文件:jquery
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)sql
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>
登陸:session
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>
登陸信息是否正確判斷,正確則進入聊天室app
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後臺處理)dom
注:因爲是後面才加的分類,因此對沒有修改之前直接提交的form表單post
先是判斷是否登陸:
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=" width: 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=" width: 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=" width: 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=" width: 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=" width: 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=" width: 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=" width: 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=" width: 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>