數據庫教程連接程序
sub opensql()
set sqlrs=server.CreateObject("adodb.recordset")
set sqlcn=server.createobject("adodb.connection")
sqlconstr="driver={sql server};server=xiewen;uid=sa;pwd=123456;database=jimmy"
sqlcn.open sqlconstr
end sub
//功能處理程序asp教程把內容保存到數據庫
<%dim f_id,tag,names,lytxt
f_id=request.QueryString("id")
tag=request.QueryString("tag")
lytxt=html_encode(request.Form("lytxt"))
names=session("lyname")
if names="" then
names="匿名"
end if
if (not isnumeric(f_id)) or (not isnumeric(tag)) or len(lytxt)<5 then
response.Write("<script language='javascript教程'>alert('文章內容不能少於五個字符!');history.back();</script>")
else
sql="select * from guestbook"
on error resume next
call opensql()
sqlrs.open sql,sqlcn,1,3
sqlrs.addnew
sqlrs("ly")=lytxt
sqlrs("f_id")=f_id
sqlrs("tag")=tag
sqlrs("name")=names
sqlrs.update
if err=0 then
response.Redirect("list.asp?id="&f_id&"&tag="&tag)
else
response.Write("<script language='javascript'>alert('非常抱歉,您的留言失敗!');history.back();</script>")
end if
end if
%>
html提供頁面
<input name=lytxt >
<input type=submit value提交 />