savearticle.asp
'同上這也是安全的保證!
<%
if request.cookies("adminok")="" then
response.redirect "login.asp"
end if
%>
<%
'判斷字元段是否為空白!如果不加判斷會對儲存資料庫造成影響!
if request.form("txttitle")="" then
response.write "錯誤提示:未輸入標題!"
'顯示問題,強制暫停 response.end就是這個用處!
'大家可從中慢慢體會!
response.end
end if
'同上
if request.form("txtcontent")="" then
response.write "錯誤提示:未輸入內容!"
response.end
end if
%>
'articleconn.asp是資料庫連接位置,分開放是因為資料庫是可下載的!
'以後使用者改資料庫名可保正不被人看到
<!--#include file="articleconn.asp"-->
'這是自動換行的標識判斷程式!
'大家可下載動感首頁更新看到,慢慢研究!
<!--#include file="inc/articlechar.inc"-->
<%
'dim定義變數,VB愛好者的當然相當熟悉了(注意:不可重複定義)
dim listname
dim url
dim title
dim content
dim sql
dim rs
dim filename
dim articleid
dim outfile
'htmlencode2看了articlechar.inc進行過濾
'注意:txttitle,txtcontent,txturl的變化(幾乎所有的ASP程式的關鍵)
'阿喔認為,動感萬不變,只有字元段變化,這是方便更新的關鍵!
'
title=htmlencode2(request.form("txttitle"))
content=htmlencode2(request.form("txtcontent"))
url=htmlencode2(request.form("txturl"))
'連結資料庫articleconn.asp以幫你作了!
'現在知道include的妙用了吧!
'阿喔的http://asp.on.net.cn/都使用了include其方便更新幫了阿喔
'一個大忙!
set rs=server.createobject("adodb.recordset")
sql="select * from learning where (articleid is null)"
'開啟資料庫 conn,1,3中3是關鍵,寫的意思可別少了!
rs.open sql,conn,1,3
'添加新的資料
rs.addnew
'大家看三個字元右出現了RS("title")表示資料庫中項的名稱
'大家開啟new.dmb就知道了!三個變數賦予資料庫
rs("title")=title
rs("content")=content
rs("url")=url
rs("dateandtime")=date()
rs.update
'ID為自動添加!
articleid=rs("articleid")
關閉資料庫是一個習慣,要不然會影響伺服器速度,造成系統崩潰!
rs.close
set rs=noting
conn.close
set conn=nothing
'完成頁面添加後制動進入index.asp頁
response.redirect "index.asp"
%>
大家注意的是兩點:
1.判斷句資料是否為空白是必要的,要不然會造成資料無法添加
2.Txttitle,txtil和txtcontent文欄位,如何提交的資料庫是關鍵
作者:阿喔 出處:<ASP動感線上> http://asp.on.net.cn/
(待續)