接着:if name=\"\" or title=\"\" or body=\"\" then
判断name、title和body变量中是否没有填写内容,即为\"\",如果这样,就执行这一语句:
“请<a href=\"****:history.go(-1)\">后退</a>填写完整资料,你才能发表帖子!”
该语句属于html语法,大家都看得懂的!
\"<%else%>\"就是说“当if……then不成立(即是说所有内容都已经填写)”,就执行语句:
“<%set savebbs=conn.execute(\"insert into bbs(name,title,body) values(\'\"&name&\"\',\'\"&title&\"\',\'\"&body&\"\')\")%>
发表成功!<a href=\"index.asp\">查看帖子</a>”
\"set save=conn.execute\"属于固定的语句,不过savebbs可以自己修改,\"=\"后面的就难解释了:
insert into bbs(name,title,body)意思是向名为bbs的表(在建立数据库时已经建立的表)
中的name,title,body字段插入,插入什么呢?看接下的values(\'\"&name&\"\',\'\"&title&\"\',\'\"&body&\"\')\")
values是“值”的意思
就是插入向量name,title,body,向量用格式\'\"&name&\"\'表示
最后:end if就是结束if……then
set savebbs=nothing可以说是关闭掉:
set savebbs=conn.execute(\"insert into bbs(name,title,body) values(\'\"&name&\"\',\'\"&title&\"\',\'\"&body&\"\')\")
5、index.asp
源代码:
<!--#include file=\"conn.asp\"-->
<b><a href=\"say.asp\">发表帖子</a></b><br><br>
<div align=\"center\">
<center>
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; \" bordercolor=\"#000000\" width=\"100%\" height=\"26\">
<tr>
<td width=\"17%\"><b>作者</b></td>
<td width=\"83%\"><b>主题</b></td>
</tr>
</table>
</center>
</div><hr size=\"1\">
<%i=1
set showbbs=conn.execute(\"select*from bbs order by id desc\")
do while not showbbs.eof
%>
<div align=\"center\">
<center>
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; \" bordercolor=\"#000000\" width=\"100%\" height=\"20\">
<tr>
<td width=\"17%\"><%=showbbs(\"name\")%> </td>
<td width=\"83%\">
<a href=\"show.asp?id=<%=showbbs(\"id\")%>\"><%=showbbs(\"title\")%></a></td>
</tr>
</table>
</center>
</div><hr size=\"1\">
<%i=i+1
if i>50 then exit do
showbbs.movenext
Loop
showbbs.Close
set showbbs=nothing
%>
这个文件就不一句一句的讲了
主要讲精华部分:
set showbbs=conn.execute(\"select*from bbs order by id desc\")
意思是:向数据库中的bbs数据表查询数据,并以id排顺序,
还有这么一句:<%=showbbs(\"name\")%>
就是显示数据表中的name字段的数据,这里的showbbs就是set showbbs=……中的showbbs
代码中的i=1和i=i+1
if i>50 then exit do
showbbs.movenext
Loop
showbbs.Close
set showbbs=nothing
这几句属于循环语句,这里就不理他,理解了也不太好用,因为他只显示50张贴子!
if i>50 then exit do中的50可以修改
但我们做论坛必须把帖子分页,又因为分页这个语句太复杂,我想就不讲了,等这一个弄懂了才来弄
还有一句很有用的:
<a href=\"show.asp?id=<%=showbbs(\"id\")%>\"><%=showbbs(\"title\")%></a>
里面的超连接:show.asp?id=<%=showbbs(\"id\")%>,注意:这里的超连接把帖子的id包含了,
等一下在show.asp文件中就有用了