1.编写html页面
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<form action="jobaddsave.php" method="post">
招聘标题:<input type="text" name="title"><br>
招聘要求:<textarea cols="10" rows="5" name="content">
</textarea><br>
<input type="submit" value="提交">
</form>
</body>
</html>
2.编写jobaddsave.php页面,通过html页面把数据保存到数据库中
<?php
include '../inc/db_mysqli.php';
$_POST['utime']=time();
save('hnsc_job',$_POST);
header('location:jobadmin.php');
?>
3.数据库中创建数据库表格hnsc_job
create table hnsc_job(
id int unsigned auto_increment,
title varchar(30),
content text,
utime int,
primary key(id)
)engine=myisam default charset=utf8;
4.查询数据库
select * from hnsc_job
5.实现网站前台,显示添加的内容加入如下代码
<?php
$rows = query('hnsc_job');
$i = 0;
foreach($rows as $v){
echo '<h1>'.++$i.'、'.$v[1].'</h1>';
echo nl2br($v[2]).'<br>';
}
?>
nl2br — 在字符串所有新行之前插入 HTML 换行标记
后台显示修改jobadmin.php
<?php
include '../inc/db_mysqli.php';
//删除友情链接信息
if(isset($_GET['del'])){
$stmt=$m->prepare('delete from hnsc_job where id=?');
$dd=$_GET['del'];
$stmt->bind_param('i',$dd);
$stmt->execute();
$stmt->free_result();
$stmt->close();
}
//预处理语句查询数据
$stmt=$m->prepare('select * from hnsc_job order by id desc');
$stmt->execute();
$result=$stmt->get_result();
$rows=$result->fetch_all(2);
$stmt->free_result();
$stmt->close();
$m->close();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="keywords" content="关键字">
<meta name="description" content="简介">
<script src=""></script>
<style>
th {
font-size: 14px;
letter-spacing: 2px;
background-color: #efefef;
padding: 15px;
}
tr {
background-color: #FFFFFF;
}
td {
padding: 10px;
text-align:center;
font-size:12px;
}
</style>
</head>
<body>
<table cellspacing="1" border="0" width="80%" bgcolor="#BFBFBF" align="center">
<tr bgcolor="#FFFFFF">
<th>标题</th>
<th>招聘内容</th>
<th>加入时间</th>
<th>操作</th>
</tr>
<?php
foreach($rows as $v){
?>
<tr>
<td><?=$v[1]?></td>
<td><?=$v[2]?></td>
<td><?=date('Y-m-d H:i:s',$v[3])?></td>
<td>
<a href="?del=<?=$v[0]?>" onClick="return confirm('是否要删除?')">删除</a>
</td>
</tr>
<?php
}
?>
</table>
<a href="jobaddd.html">添加新的招聘信息</a>
</body>
</html>