实训作业留言本的制作Word格式文档下载.docx
《实训作业留言本的制作Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《实训作业留言本的制作Word格式文档下载.docx(23页珍藏版)》请在冰点文库上搜索。
![实训作业留言本的制作Word格式文档下载.docx](https://file1.bingdoc.com/fileroot1/2023-5/1/e5ef3261-bc70-4c88-9da5-86262d97d531/e5ef3261-bc70-4c88-9da5-86262d97d5311.gif)
admin和guestbook
(1)表1:
admin
标注
字段名
类型
长度
1
uid
int
4
2
username
varchar
20
3
userpass
(2)表2:
guestbook
id
nickname
char
16
email
60
face
tinyint
5
content
text
6
createtime
10
7
clientip
15
8
reply
9
replytime
五、创建数据库
1)创建数据库:
2)建表:
表1:
表2:
共六个页面:
1.conn.php:
数据库连接包含文件
2.config.php:
统配置文件,用于配置每页显示留言条数等
3.index.php:
留言板主界面,用于留言读取显示及用户留言表单(留言表单在留言显示下方)
4.subting.php:
处理留言者提交的留言信息
5.login.php:
管理员登录及验证页面
6.admin.php:
留言管理主界面,读取留言数据,提供回复表单及删除等操作界面
7.reply.php:
用于留言回复,删除等具体操作
●conn.php代码如下:
<
?
php
/*****************************
*数据库连接
*****************************/
$conn=@mysql_connect("
localhost"
"
root"
);
if(!
$conn){
die("
连接数据库失败:
"
.mysql_error());
}
mysql_select_db("
test"
$conn);
//字符转换,读库
mysql_query("
setcharacterset'
gbk'
//写库
setnames'
>
●config.php代码如下:
$pagesize=8;
//每页显示的留言数
●index.php代码如下:
!
DOCTYPEhtml>
html>
head>
metacharset="
gb2312"
/>
linkrel="
stylesheet"
type="
text/css"
href="
style/style.css"
title>
请您留言<
/title>
scriptlanguage="
JavaScript"
functionInputCheck(form1)
{
if(form1.nickname.value=="
)
{
alert("
请输入您的昵称。
form1.nickname.focus();
return(false);
}
if(form1.content.value=="
留言内容不可为空。
form1.content.focus();
/script>
/head>
body>
divid="
container"
guestbook"
--留言列表-->
h3>
留言列表<
/h3>
//引用相关文件
require("
./conn.php"
./config.php"
//确定当前页数$p参数
$p=$_GET['
p'
]?
$_GET['
]:
1;
//数据指针
$offset=($p-1)*$pagesize;
$query_sql="
SELECT*FROMguestbookORDERBYidDESCLIMIT$offset,$pagesize"
;
$result=mysql_query($query_sql);
//如果出现错误并退出
if(!
$result)exit('
查询数据错误:
'
.mysql_error());
//循环输出
while($gb_array=mysql_fetch_array($result)){
divclass="
guestbook-list"
pclass="
guestbook-head"
imgsrc="
images/<
phpecho$gb_array['
face'
.gif"
spanclass="
bold"
nickname'
/span>
<
guestbook-time"
[<
phpechodate("
Y-m-dH:
i"
$gb_array['
createtime'
])?
]<
/p>
guestbook-content"
phpechonl2br($gb_array['
content'
//回复
if(!
empty($gb_array['
replytime'
])){
管理员回复:
reply'
}//回复结束
/div>
}//while循环结束
guestbook-listguestbook-page"
p>
//计算留言页数
$count_result=mysql_query("
SELECTcount(*)FROMguestbook"
$count_array=mysql_fetch_array($count_result);
$pagenum=ceil($count_array['
count(*)'
]/$pagesize);
echo'
共'
$count_array['
],'
条留言'
if($pagenum>
1){
for($i=1;
$i<
=$pagenum;
$i++){
if($i==$p){
echo'
&
nbsp;
['
$i,'
]'
}else{
ahref="
index.php?
p='
.$i.'
/a>
}
--留言列表结束-->
guestbook-form"
发表留言<
tableborder="
1"
cellpadding="
0"
cellspacing="
style="
border-collapse:
collapse"
align="
center"
width="
600"
bgcolor="
#000000"
tr>
tdheight="
100"
#6c6c6c"
fontstyle="
font-size:
30px"
color="
#ffffff"
face="
TimesNewRoman,Times,serif"
/font>
/td>
25"
&
ahref=index.php>
[查看留言]<
login.php"
[管理留言]<
/tr>
200"
formid="
form1"
name="
method="
post"
action="
submiting.php"
onSubmit="
returnInputCheck(this)"
labelfor="
title"
fontcolor="
#FFFF00"
昵&
称:
/label>
inputid="
nickname"
text"
span>
(必须填写,不超过16个字符串)<
电子邮件:
email"
(非必须,不超过60个字符串)<
face"
头&
像:
inputtype="
radio"
value="
checked>
images/1.gif"
2"
images/2.gif"
3"
images/3.gif"
4"
images/4.gif"
5"
images/5.gif"
6"
images/6.gif"
7"
images/7.gif"
leftmargin"
8"
images/8.gif"
9"
images/9.gif"
10"
images/10.gif"
11"
images/11.gif"
12"
images/12.gif"
13"
images/13.gif"
14"
images/14.gif"
留言内容:
textareaid="
content"
/textarea>
submit"
class="
确定"
(请自觉遵守互联网相关政策法规,严禁发布色情、暴力、反动言论)<
/form>
/table>
--container-->
/body>
/html>
运行效果如图:
●subting.php代码如下:
//禁止非POST方式访问
isset($_POST['
submit'
])){
exit('
非法访问!
//表单信息处理
if(get_magic_quotes_gpc()){
$nickname=htmlspecialchars(trim($_POST['
]));
$email=htmlspecialchars(trim($_POST['
email'
$content=htmlspecialchars(trim($_POST['
}else{
$nickname=addslashes(htmlspecialchars(trim($_POST['
])));
$email=addslashes(htmlspecialchars(trim($_POST['
$content=addslashes(htmlspecialchars(trim($_POST['
if(strlen($nickname)>
16){
错误:
昵称不得超过16个字符串[<
javascript:
history.back()"
返回<
]'
60){
邮箱不得超过60个字符串[<
conn.php"
function.php"
$createtime=time();
$ip=get_client_ip();
//数据写入库表
$insert_sql="
INSERTINTOguestbook(nickname,email,face,content,createtime,clientip)VALUES"
$insert_sql.="
('
$nickname'
'
$email'
$_POST[face],'
$content'
$createtime,'
$ip'
)"
if(mysql_query($insert_sql)){
DOCTYPEhtmlPUBLIC"
-//W3C//DTDXHTML1.0Transitional//EN"
"
http:
//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
htmlxmlns="
//www.w3.org/1999/xhtml"
metahttp-equiv="
Content-Type"
content="
text/html;
charset=gb2312"
Refresh"
2;
url=index.php"
留言成功<
refresh"
留言成功!
非常感谢您的留言。
br/>
请稍后,页面正在返回...<
echo'
留言失败:
mysql_error(),'
[<
●login.php代码如下:
include"
//接受用户名和密码
$username=$_POST["
username"
];
$userpass=$_POST["
password"
//如果是点击“登陆”后,则进行验证用户身份
if($username!
="
){
//检验用户名是否存在
$query="
select*fromadminwhereusername='
$username'
echo$query;
$rst=mysql_query($query);
if(mysql_num_rows($rst)==0){
echo"
用户名不存在,请重新输入!
}else{
$info=mysql_fetch_array($rst);
//检验密码是否正确
echo$info["
userpass"
echo$userpass;
if($info["
]!
=$userpass){
echo"
登录密码输入错误,请重新输入!
//注册session,做后台管理页登陆的身份验证
//session_start();
//$_SESSION["
]=$info["
setcookie("
$info["
],0,"
/"
//更新最后登陆时间
//$today=date("
i:
s"
//$query="
updatebuy_user_inforsettime='
$today'
whereusername='
andserpass='
$userpass'
//$folie->
excu($query);
//跳转到后台管理页
header("
location:
./admin.php"
留言管理登录<
--
if(form1.password.value=="
请输入密码。
form1.password.focus();
//--!
login-form"
admin"
管理密码:
index.php"
返回留言板<
●admin.php代码如下:
*admin.php后台管理主页面文件
//session_start();
//未登录则重定向到登陆页面
$_COOKIE['
username'
]){
header("
Location:
http:
//"
.$_SERVER['
HTTP_HOST'
].rtrim(dirname($_SERVE