2020年5月8日

    1. <?php
    2. $post=$_POST;
    3. var_dump($post);
    4. include './functions.php';
    5. $sql=sprintf("INSERT INTO comment VALUES(DEFAULT,'%s','%s','%s'),$post['comment'],$post['name'],$post['email']");
    6. $res= execute($sql);
    7. if($res){
    8. echo"成功";
    9. }else{
    10. echo"失败"
    11. }
    12. function query($sql);
    13. $link=mysqli_connect('127.0.0.1','root','root','liuyan')or exit('连接数据库失败');
    14. mysqli_set_charset($link,'UTF8');
    15. if($resfalse){
    16. echo mysqli_errno($link),"<br>";
    17. echo mysqli_error($link),"<br";
    18. exit('sql语句执行失败');
    19. }
    20. $data=[];
    21. while($row=mysqli_fetch_assoc($res)){
    22. $data[]=$row;
    23. }
    24. mysqli_free_result($res);
    25. mysqli_close($link);
    26. return $data;
    27. }
    28. function execute($sql){
    29. $link = mysqli_connect('127.0.0.1','root','root','liuyan')or exit('连接数据库失败');
    30. mysqli_set_charset($link,'UTF8');
    31. $res=mysqli_query($link,$sql);
    32. $aff=mysqli_affected_rows($link);
    33. mysqli_close($$link);
    34. if($res && $aff > 0){
    35. return true;
    36. }else{
    37. return false;
    38. }
    39. }
    40. include '/.demo.php';
    41. $sql="SELECT *FROM comment ORDER BY id DESC";
    42. $data = query($sql);
    43. ?>
    44. <!DOCTYPE html>
    45. <html>
    46. <head>
    47. <meta charset="utf-8">
    48. <title>内容</title>
    49. <styl>
    50. </style>
    51. </head>
    52. <body>
    53. <h1>留言板</h1>
    54. <p>
    55. <a herf="./add.php">添加留言</a>
    56. </p>
    57. <?php forseach($data as $key$liuyan){ ?>
    58. <div class="cb">
    59. <p><? php echo $liuyan['content']?></p>
    60. <div class="ca">
    61. <b><? php echo $liuyan['name']?></b><span><?php echo $liuyan['email']?></span></div>
    62. <div class="c-act">
    63. <a herf="">编辑</a>
    64. <a herf="">删除</a>
    65. </div>
    66. </div>
    67. <?php } ?>
    68. </body>
    69. </html>
    70. <?php
    71. include './functions.php';
    72. $sql="SELECT *FROM comment ORDER BY id DESC";
    73. $data=query($sql);
    74. ?>
    75. <!DOCTYPE html>
    76. <html>
    77. <head>
    78. <meta charset="utf-8">
    79. <title>内容</title>
    80. <styl>
    81. .cb{
    82. border:1px solid red;
    83. }
    84. </style>
    85. </head>
    86. <body>
    87. <h1>留言板</h1>
    88. <p><a herf="./add.php">添加留言</a></p>
    89. <?php forseach($data as $key$liuyan){ ?>
    90. <div class="cb">
    91. <p><? php echo $liuyan['content']?></p>
    92. <div class="ca">
    93. <b><? php echo $liuyan['name']?></b><span><?php echo $liuyan['email']?></span></div>
    94. <div class="c-act">
    95. <a herf="./edit.php?id=<?php echo $liuyan['id']?>">编辑</a>
    96. <a herf="./del.php?id=<?php echo $liuyan['id']?>">删除</a>
    97. </div>
    98. </div>
    99. <?php } ?>
    100. </body>
    101. </html>
    102. <?php
    103. $id=$_GET['id'];
    104. var_dump($id);
    105. $sql="DELETE FROM comment WHERE id={$id}";
    106. include './functions.php';
    107. $res=execute($sql);
    108. if($res){
    109. echo"成功"
    110. }esle{
    111. echo"失败“;
    112. }
    113. <?php
    114. var_dump($_POST);
    115. $id=$_POST['id'];
    116. $content=$_POST['comment'];
    117. $sql=sprintf("UPDATE comment SET content='%s' WHERE id =%s",$content,$id);
    118. include './functions.php';
    119. $res=execute($sql);
    120. if($res){
    121. echo"成功";
    122. }else{
    123. echo"失败";
    124. }
    125. <?php
    126. $post=$_POST;
    127. var_dump($post);
    128. include './functions.php';
    129. $sql=sprintf("INSERT INTO comment VALUES(DEFAULT,'%s','%s','%s'),$post['comment'],$post['name'],$post['email']");
    130. $res= execute($sql);
    131. if($res){
    132. echo"成功";
    133. }else{
    134. echo"失败"
    135. }
    136. function query($sql);
    137. $link=mysqli_connect('127.0.0.1','root','root','liuyan')or exit('连接数据库失败');
    138. mysqli_set_charset($link,'UTF8');
    139. if($res≡false){
    140. echo mysqli_errno($link),"<br>";
    141. echo mysqli_error($link),"<br";
    142. exit('sql语句执行失败');
    143. }
    144. $data=[];
    145. while($row=mysqli_fetch_assoc($res)){
    146. $data[]=$row;
    147. }
    148. mysqli_free_result($res);
    149. mysqli_close($link);
    150. return $data;
    151. }
    152. function execute($sql){
    153. $link = mysqli_connect('127.0.0.1','root','root','liuyan')or exit('连接数据库失败');
    154. mysqli_set_charset($link,'UTF8');
    155. $res=mysqli_query($link,$sql);
    156. $aff=mysqli_affected_rows($link);
    157. mysqli_close($$link);
    158. if($res && $aff > 0){
    159. return true;
    160. }else{
    161. return false;
    162. }
    163. }
    164. include '/.demo.php';
    165. $sql="SELECT *FROM comment ORDER BY id DESC";
    166. $data = query($sql);
    167. ?>
    168. <!DOCTYPE html>
    169. <html>
    170. <head>
    171. <meta charset="utf-8">
    172. <title>内容</title>
    173. <styl>
    174. </style>
    175. </head>
    176. <body>
    177. <h1>留言板</h1>
    178. <p>
    179. <a herf="./add.php">添加留言</a>
    180. </p>
    181. <?php forseach($data as $key$liuyan){ ?>
    182. <div class="cb">
    183. <p><? php echo $liuyan['content']?></p>
    184. <div class="ca">
    185. <b><? php echo $liuyan['name']?></b><span><?php echo $liuyan['email']?></span></div>
    186. <div class="c-act">
    187. <a herf="">编辑</a>
    188. <a herf="">删除</a>
    189. </div>
    190. </div>
    191. <?php } ?>
    192. </body>
    193. </html>
    194. <?php
    195. include './functions.php';
    196. $sql="SELECT *FROM comment ORDER BY id DESC";
    197. $data=query($sql);
    198. ?>
    199. <!DOCTYPE html>
    200. <html>
    201. <head>
    202. <meta charset="utf-8">
    203. <title>内容</title>
    204. <styl>
    205. .cb{
    206. border:1px solid red;
    207. }
    208. </style>
    209. </head>
    210. <body>
    211. <h1>留言板</h1>
    212. <p><a herf="./add.php">添加留言</a></p>
    213. <?php forseach($data as $key$liuyan){ ?>
    214. <div class="cb">
    215. <p><? php echo $liuyan['content']?></p>
    216. <div class="ca">
    217. <b><? php echo $liuyan['name']?></b><span><?php echo $liuyan['email']?></span></div>
    218. <div class="c-act">
    219. <a herf="./edit.php?id=<?php echo $liuyan['id']?>">编辑</a>
    220. <a herf="./del.php?id=<?php echo $liuyan['id']?>">删除</a>
    221. </div>
    222. </div>
    223. <?php } ?>
    224. </body>
    225. </html>
    226. <?php
    227. $id=$_GET['id'];
    228. var_dump($id);
    229. $sql="DELETE FROM comment WHERE id={$id}";
    230. include './functions.php';
    231. $res=execute($sql);
    232. if($res){
    233. echo"成功"
    234. }esle{
    235. echo"失败“;
    236. }
    237. <?php
    238. var_dump($_POST);
    239. $id=$_POST['id'];
    240. $content=$_POST['comment'];
    241. $sql=sprintf("UPDATE comment SET content='%s' WHERE id =%s",$content,$id);
    242. include './functions.php';
    243. $res=execute($sql);
    244. if($res){
    245. echo"成功";
    246. }else{
    247. echo"失败";
    248. }
    249. <?php
    250. $post=$_POST;
    251. var_dump($post);
    252. include './functions.php';
    253. $sql=sprintf("INSERT INTO comment VALUES(DEFAULT,'%s','%s','%s'),$post['comment'],$post['name'],$post['email']");
    254. $res= execute($sql);
    255. if($res){
    256. echo"成功";
    257. }else{
    258. echo"失败"
    259. }
    260. function query($sql);
    261. $link=mysqli_connect('127.0.0.1','root','root','liuyan')or exit('连接数据库失败');
    262. mysqli_set_charset($link,'UTF8');
    263. if($res≡false){
    264. echo mysqli_errno($link),"<br>";
    265. echo mysqli_error($link),"<br";
    266. exit('sql语句执行失败');
    267. }
    268. $data=[];
    269. while($row=mysqli_fetch_assoc($res)){
    270. $data[]=$row;
    271. }
    272. mysqli_free_result($res);
    273. mysqli_close($link);
    274. return $data;
    275. }
    276. function execute($sql){
    277. $link = mysqli_connect('127.0.0.1','root','root','liuyan')or exit('连接数据库失败');
    278. mysqli_set_charset($link,'UTF8');
    279. $res=mysqli_query($link,$sql);
    280. $aff=mysqli_affected_rows($link);
    281. mysqli_close($$link);
    282. if($res && $aff > 0){
    283. return true;
    284. }else{
    285. return false;
    286. }
    287. }
    288. include '/.demo.php';
    289. $sql="SELECT *FROM comment ORDER BY id DESC";
    290. $data = query($sql);
    291. ?>
    292. <!DOCTYPE html>
    293. <html>
    294. <head>
    295. <meta charset="utf-8">
    296. <title>内容</title>
    297. <styl>
    298. </style>
    299. </head>
    300. <body>
    301. <h1>留言板</h1>
    302. <p>
    303. <a herf="./add.php">添加留言</a>
    304. </p>
    305. <?php forseach($data as $key$liuyan){ ?>
    306. <div class="cb">
    307. <p><? php echo $liuyan['content']?></p>
    308. <div class="ca">
    309. <b><? php echo $liuyan['name']?></b><span><?php echo $liuyan['email']?></span></div>
    310. <div class="c-act">
    311. <a herf="">编辑</a>
    312. <a herf="">删除</a>
    313. </div>
    314. </div>
    315. <?php } ?>
    316. </body>
    317. </html>
    318. <?php
    319. include './functions.php';
    320. $sql="SELECT *FROM comment ORDER BY id DESC";
    321. $data=query($sql);
    322. ?>
    323. <!DOCTYPE html>
    324. <html>
    325. <head>
    326. <meta charset="utf-8">
    327. <title>内容</title>
    328. <styl>
    329. .cb{
    330. border:1px solid red;
    331. }
    332. </style>
    333. </head>
    334. <body>
    335. <h1>留言板</h1>
    336. <p><a herf="./add.php">添加留言</a></p>
    337. <?php forseach($data as $key$liuyan){ ?>
    338. <div class="cb">
    339. <p><? php echo $liuyan['content']?></p>
    340. <div class="ca">
    341. <b><? php echo $liuyan['name']?></b><span><?php echo $liuyan['email']?></span></div>
    342. <div class="c-act">
    343. <a herf="./edit.php?id=<?php echo $liuyan['id']?>">编辑</a>
    344. <a herf="./del.php?id=<?php echo $liuyan['id']?>">删除</a>
    345. </div>
    346. </div>
    347. <?php } ?>
    348. </body>
    349. </html>
    350. <?php
    351. $id=$_GET['id'];
    352. var_dump($id);
    353. $sql="DELETE FROM comment WHERE id={$id}";
    354. include './functions.php';
    355. $res=execute($sql);
    356. if($res){
    357. echo"成功"
    358. }esle{
    359. echo"失败“;
    360. }
    361. <?php
    362. var_dump($_POST);
    363. $id=$_POST['id'];
    364. $content=$_POST['comment'];
    365. $sql=sprintf("UPDATE comment SET content='%s' WHERE id =%s",$content,$id);
    366. include './functions.php';
    367. $res=execute($sql);
    368. if($res){
    369. echo"成功";
    370. }else{
    371. echo"失败";
    372. }