注册 登录
编程论坛 ASP技术论坛

提示留言成功,但不会写进数据库,什么原因?

huiyi6802 发布于 2011-11-05 18:22, 1208 次点击
<!--#include file="conn.asp"-->
<%
'Response.Addheader "Content-Type","text/html; charset=gb2312"
Response.Charset="GB2312"
ip=request.servervariables("REMOTE_ADDR")
title=nohtml(request.form("title"))
name=nohtml(request.form("name"))
tel=nohtml(request.form("tel"))
content=nohtml(request.form("content"))
code=Get_SafeStr(request.form("code"))


Function telpd(strPassword)
    Dim regEx
    Set regEx = new RegExp
    regEx.IgnoreCase = false
    regEx.global = false
    regEx.Pattern = "(^0[0-9]{2,3}-[0-9]{7,8}$)|(^0?1[0-9]{10}$)"
    if regEx.Test(strPassword) then
        telpd = true
    else
        telpd = false
    end if
    set regEx = Nothing
End Function

function incode(fString)
if not isnull(fString) then
    fString = Replace(fString, CHR(9), "&nbsp;")
    fString = Replace(fString, CHR(10) & CHR(10), "</p><p>")
    fString = Replace(fString, CHR(10), "<br/>")
    incode = fString
end if
end function

if Code<>CStr(session("CheckCode")) then
response.write "验证码不正确"
response.end
end if

if title=""  then
response.write "留言主题不能为空"
response.end
end if
if name="" then
response.write "您的姓名不能为空"
response.end
end if

if telpd(tel)=false then
response.write "电话号码填写不正确,请重新填写!格式如:0592-5983163或13400693163"
response.end
end if

if content="" then
response.write "内容不能为空"
response.end
end if
content=incode(content)

conn.execute("insert into book(title,name,tel,content,ip) values('"&title&"','"&name&"','"&tel&"','"&content&"','"&ip&"')")
response.write "留言成功"
conn.close:set conn=nothing
response.end
%>
8 回复
#2
孤独冷雨2011-11-05 19:15
你用update试试应该可以的!
#3
huiyi68022011-11-05 19:35
为什么要用update,不是直接插入就行吗?
#4
huiyi68022011-11-05 19:36
回复 2楼 孤独冷雨
update是用来修改数据的呀。
#5
孤独冷雨2011-11-05 19:38
rs.addrew
*****
*****
*****
rs.update
#6
huiyi68022011-11-05 20:15
回复 5楼 孤独冷雨
conn.addnew
conn("title")=request.form("title")
conn("name")=request.form("name")
conn("tel")=request.form("tel")
conn("content")=request.form("content")
conn.update

改成以上的后,连提示留言成功都没了,同样没写进数据库。
conn.execute("insert into book(title,name,tel,content,ip) values('"&title&"','"&name&"','"&tel&"','"&content&"','"&ip&"')")
用这个提示成功,但写不进数据库
#7
huiyi68022011-11-05 21:25
总是还没有解决呀,高手来指点一下呀,不然又要卡住了。
#8
wangjy5002011-11-06 12:18
conn.execute("insert into book(title,name,tel,content,ip) values('aaa','bbb','ccc','ddddd','eeee')")

改成这样看能插入不,,,?

#9
netbooting2011-11-09 10:50
回复 6楼 huiyi6802
第1步:
SQL = "insert into book(title,name,tel,content,ip) values('"&title&"','"&name&"','"&tel&"','"&content&"','"&ip&"')"
Response.write SQL
看看SQL语句有没有问题

第2步:
conn.Execute() 把后面的括号去掉

第3步:
检查数据库的数据结构有没有问题,是不是都是文本类型
1