1.编写html页面
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>无标题文档</title>
  6. </head>
  7. <body>
  8. <form action="jobaddsave.php" method="post">
  9. 招聘标题:<input type="text" name="title"><br>
  10. 招聘要求:<textarea cols="10" rows="5" name="content">
  11. </textarea><br>
  12. <input type="submit" value="提交">
  13. </form>
  14. </body>
  15. </html>

2.编写jobaddsave.php页面,通过html页面把数据保存到数据库中
  1. <?php
  2. include '../inc/db_mysqli.php';
  3. $_POST['utime']=time();
  4. save('hnsc_job',$_POST);
  5. header('location:jobadmin.php');
  6. ?>
3.数据库中创建数据库表格hnsc_job  
  1. create table hnsc_job(
  2. id int unsigned auto_increment,
  3. title varchar(30),
  4. content text,
  5. utime int,
  6. primary key(id)
  7. )engine=myisam default charset=utf8;
4.查询数据库
select * from hnsc_job

5.实现网站前台,显示添加的内容加入如下代码
  1. <?php
  2. $rows = query('hnsc_job');
  3. $i = 0;
  4. foreach($rows as $v){
  5. echo '<h1>'.++$i.'、'.$v[1].'</h1>';
  6. echo nl2br($v[2]).'<br>';
  7. }
  8. ?>

nl2br — 在字符串所有新行之前插入 HTML 换行标记
后台显示修改jobadmin.php
  1. <?php
  2. include '../inc/db_mysqli.php';
  3. //删除友情链接信息
  4. if(isset($_GET['del'])){
  5. $stmt=$m->prepare('delete from hnsc_job where id=?');
  6. $dd=$_GET['del'];
  7. $stmt->bind_param('i',$dd);
  8. $stmt->execute();
  9. $stmt->free_result();
  10. $stmt->close();
  11. }
  12. //预处理语句查询数据
  13. $stmt=$m->prepare('select * from hnsc_job order by id desc');
  14. $stmt->execute();
  15. $result=$stmt->get_result();
  16. $rows=$result->fetch_all(2);
  17. $stmt->free_result();
  18. $stmt->close();
  19. $m->close();
  20. ?>
  21. <!DOCTYPE html>
  22. <html>
  23. <head>
  24. <meta charset="utf-8">
  25. <title></title>
  26. <meta name="keywords" content="关键字">
  27. <meta name="description" content="简介">
  28. <script src=""></script>
  29. <style>
  30. th {
  31. font-size: 14px;
  32. letter-spacing: 2px;
  33. background-color: #efefef;
  34. padding: 15px;
  35. }
  36. tr {
  37. background-color: #FFFFFF;
  38. }
  39. td {
  40. padding: 10px;
  41. text-align:center;
  42. font-size:12px;
  43. }
  44. </style>
  45. </head>
  46. <body>
  47. <table cellspacing="1" border="0" width="80%" bgcolor="#BFBFBF" align="center">
  48. <tr bgcolor="#FFFFFF">
  49. <th>标题</th>
  50. <th>招聘内容</th>
  51. <th>加入时间</th>
  52. <th>操作</th>
  53. </tr>
  54. <?php
  55. foreach($rows as $v){
  56. ?>
  57. <tr>
  58. <td><?=$v[1]?></td>
  59. <td><?=$v[2]?></td>
  60. <td><?=date('Y-m-d H:i:s',$v[3])?></td>
  61. <td>
  62. <a href="?del=<?=$v[0]?>" onClick="return confirm('是否要删除?')">删除</a>
  63. </td>
  64. </tr>
  65. <?php
  66. }
  67. ?>
  68. </table>
  69. <a href="jobaddd.html">添加新的招聘信息</a>
  70. </body>
  71. </html>












Copyright © 2024 小蕊同学
Powered by .NET 8.0 on Kubernetes