top
Loading...
ASP技術在論壇中的運用(六)
文章發表模塊只有兩個頁面,一個是前面提到的用來提供輸入表單的submit.asp,還有一個是用來處理表單輸入的subresult.asp。前面的那個頁面很簡單,基本上就是一個HTML表單,沒有什么好講的,下面來看看subresult.asp的內容:

< html>

< head>

< title>發表文章< /title>

< meta http-equiv="Content-Type" content="text/html; charset=gb2312">

< /head>

< body bgcolor="#FFFFFF">

< %

author=request("author")

password=request("password")

topicid=request("topicid")

boardid=request("boardid")

content=request("content")

title=request("title")

這一段取出在submit.asp中提交的表但內容,放在相應的變量中。

Set conn = Server.CreateObject("ADODB.Connection")

conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("bbssystem.mdb")

Set cmd = Server.CreateObject("ADODB.Command")

Set cmd.ActiveConnection = conn

'查詢作者是否已存在

cmd.CommandText = "select * from 作者表 where id='" & author &"'"

Set rs = cmd.Execute()

'檢查權限

if rs.eof or rs.bof then

response.write "< h3>你還沒有注冊,請先< a href=register.htm>注冊< /a>後在來發表文章< /h3>"

response.write "< /body>< /html>"

response.end

end if

if password< > rs("密碼") then

response.write "< h2>密碼錯誤,請檢查密碼是否正確< /h2>"

response.write "< /body>< /html>"

response.end

end if

這一段是對作者權限進檢查,對于賬號不存在或者密碼錯誤做出相應的錯誤處理。在這兒可以看到response.end的用法,它是用來結束當前ASP腳本。結合if語句,可以對程序中的預期錯誤進行處理。在一個好的WEB應用中,錯誤處理是必不可少的。

' 將數據中的單引號改成兩個單引號,并且在前后加上單引號

Function SqlStr( data )

SqlStr = "'" & Replace( data, "'", "''" ) & "'"

End Function

'寫入數據庫

sql = "Insert Into 內容表 (看板id,主題id,作者id,標題,內容) Values( "

sql = sql & SqlStr(topicid) & ", "

sql = sql & SqlStr(boardid) & ", "

sql = sql & SqlStr(author) & ", "

sql = sql & SqlStr(title) & ", "

sql = sql & SqlStr(content) & ") "

conn.Execute sql

%>

< h2>文章已經被發送到數據庫,當板主審閱后就可以看到了< h2>

< /body>

< /html>

到這兒,文章已經被保存在數據庫中了。但是,它并不能夠立刻被顯示出來,還需要斑竹的認可才行。下面,就來看看論壇的管理部分的內容。

北斗有巢氏 有巢氏北斗