菜鸟提问:数据库写入出问题!!conn.execute(SQL)出问题

tangss 2004-01-12 03:25:36
请大家帮忙看一下:

<%'连数据库

dim conn
dim connstr
dim db
dim rescount
db="../query/ckdb.mdb" '数据库文件的位置
Set conn = Server.CreateObject("ADODB.Connection")
'connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(db)
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath(db)&";Persist Security Info=False"
if err then
err.clear
else
conn.open connstr
if err then
err.clear
end if
end if

Set rs = Server.CreateObject("ADODB.Recordset")

%>
<%
dim sql
dim name,sex,add,qq,email,links,title,con,showip,ip

'将数据中的单引号改成两个单引号,并且在前后加单引号
Function SqlStr(data)
SqlStr = "'" & Replace(data,"'","''") & "'"
End Function

name=request.form("name")
if name="" then
Response.Redirect "error.asp?errmsg=敢问阁下尊姓大名?"
' response.end
end if
name=sqlstr(name)

sex=request.form("sex")
if sex=1 then
sex="男"
elseif sex=2 then
sex="女"
else sex="不详"
end if
sex=sqlstr(sex)

add=request.form("address")
if add="" then add="天堂"
add=sqlstr(add)

qq=request.form("qq")
If qq <> "" Then
If Len(qq) < 5 or Len(qq) > 10 Then
Response.Redirect "error.asp?errmsg=QQ信息输入有误,长度不符,请返回重新输入。"
' Response.End
End IF
For I = 1 To Len(qq)
temp = Mid(qq,I,1)
If Asc(temp) < 33 Or Asc(temp) > 57 Then
Response.Redirect "error.asp?errmsg=QQ信息输入有误,含非法字符,请返回重新输入。"
' Response.End
End If
Next
else qq = "真是的,连QQ号没有"
end if
qq=sqlstr(qq)

email=request.form("email")
If email = "" Then
email = "null"
else
'检查是否包含@
If inStr(1,email,"@",0)=0 Then
Response.Redirect "error.asp?errmsg=email地址中没有@,请重新输入。"
' Response.End
End If

'¼ì²éºó׺ÊÇ·ñ´æÔÚ"."
atposition = InStr(1,email,"@")
If atposition = 1 or Instr(atposition,email,".") = 0 Then
Response.Redirect "error.asp?errmsg=email地址输入有误,请重试……"
' Response.End
End If
end if
email=sqlstr(email)

links=request.form("link")
if links="" then
links="/"
else
if inStr(1,links,".",0)=0 Then
Response.Redirect "error.asp?errmsg=网址输入有误!"
' response.end
end if
end if
links=sqlstr(links)

title=request.form("title")
if title="" then title="无题"
title=sqlstr(title)

con=request.form("content")
if con="" then
Response.Redirect "error.asp?errmsg=请无论如何留了话再走:-)"
' response.end
end if
con=sqlstr(con)
con= Replace(con,chr(13),"<BR>")

IP = Request.ServerVariables("REMOTE_ADDR")
IP = SqlStr(IP)
If Request.Form("IP") = "0" Then
showIP = SqlStr("0.0.0.0")
Else
showIP = IP
End If

sql="insert into users(name,address,qq,email,link,title,content,submittime,sex,showip,ip) values("
sql=sql & name & "," & add & "," & qq & "," & email & "," & links & "," & title & "," & con & ",'" & now() & "'," & sex & "," & showip & "," & ip & ")"
' response.write sql

set res=conn.execute(sql) '老提示这句出问题
conn.close
Set conn=Nothing
Response.Redirect "index.asp"
%>
...全文
202 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
tangss 2004-01-13
  • 打赏
  • 举报
回复
好象不是驱动是事,换了还提示同样的错误
错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
/CK/liuyan/add.asp, 第 104 行
sx1123 2004-01-13
  • 打赏
  • 举报
回复
看不出什么来。

换一个驱动看看
connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(db)

tangss 2004-01-13
  • 打赏
  • 举报
回复
错误类型:
Microsoft JET Database Engine (0x80004005)
/CK/liuyan/add.asp, 第 104 行 //就是conn.execute sql 这一行


浏览器类型:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)

页:
POST 133 bytes to /CK/liuyan/add.asp

POST 数据:
name=fff&sex=1&address=dfsdaf&ip=1&qq=34234234&email=tt@sina.com&link=www.sina.com&title=ffdfgf&content=fggfgffg&Submit=%CC%E1+%BD%BB

时间:
2004年1月13日, 11:17:17
sx1123 2004-01-13
  • 打赏
  • 举报
回复
把出错提示贴出来看看
tangss 2004-01-13
  • 打赏
  • 举报
回复
而同样的语句
insert into users(name,address,qq,email,link,title,content,submittime,sex,showip,ip) values('ddd','192.168.1.8','455454546','rr@sina.com','www.sina.com','fdt','fgwter','2004-1-13 10:48:21','男','127.0.0.1','127.0.0.1')
在Delphi中就是正确的,可以正确写入数据库中,不知为何?
tangss 2004-01-13
  • 打赏
  • 举报
回复
reaperwu(RQ) 的语句结果是:
INSERT INTO users(name,address,qq,email,link,title,content,submittime,sex,showip,ip) values(''dddd'',''192.168.1.8'',''343254'',''tt@sina.com'',''www.sina.com'',''4ewtr'',''fdstgfsdfg'','2004-1-13 10:53:43','男',''127.0.0.1'',''127.0.0.1'')


而我原来的是:
insert into users(name,address,qq,email,link,title,content,submittime,sex,showip,ip) values('ddd','192.168.1.8','455454546','rr@sina.com','www.sina.com','fdt','fgwter','2004-1-13 10:48:21','男','127.0.0.1','127.0.0.1')

还是出错误,不知什么原因,请高手不吝指教!
iright 2004-01-13
  • 打赏
  • 举报
回复
同意 61(儿童节快乐)
楼主检查一下时间,不能当字符处理,要加“#”
xlou 2004-01-13
  • 打赏
  • 举报
回复
你用response.write sql
把你的sql语句写出来 到access的sql执行中看看 如果没有问题

那就是你的数据库连接有问题 注意参数不能为1!
tangss 2004-01-13
  • 打赏
  • 举报
回复
类型没什么问题啊,
而同样的语句
insert into users(name,address,qq,email,link,title,content,submittime,sex,showip,ip) values('ddd','192.168.1.8','455454546','rr@sina.com','www.sina.com','fdt','fgwter','2004-1-13 10:48:21','男','127.0.0.1','127.0.0.1')
在Delphi中就是正确的,可以正确写入数据库中,不知为何?
jim_k 2004-01-13
  • 打赏
  • 举报
回复
检查字段类型与参数类型
61 2004-01-13
  • 打赏
  • 举报
回复
你是Access数据库?
1、insert into users(name,address,qq,email,link,title,content,submittime,sex,showip,ip) values('ddd','192.168.1.8','455454546','rr@sina.com','www.sina.com','fdt','fgwter','#2004-1-13 10:48:21#','男','127.0.0.1','127.0.0.1')
时间必须是:'#时间#'
2、检查数据库文件的操作全限是否是完全。
tangss 2004-01-13
  • 打赏
  • 举报
回复
还有人会吗?
reaperwu 2004-01-12
  • 打赏
  • 举报
回复
sql="INSERT INTO users(name,address,qq,email,link,title,content,submittime,sex,showip,ip) values("

sql=sql & "'" & name & "','" & add & "','" & qq & "','" & email & "','" & links & "','" & title & "','" & con & "','" & now() & "'," & sex & ",'" & showip & "','" & ip & "')"
qwater 2004-01-12
  • 打赏
  • 举报
回复
SQL语句用单引号
Zhang4230515 2004-01-12
  • 打赏
  • 举报
回复
检查一下你的数据类型和数据库的设置的类型,如果两者不是一样的就会出现问题。
还有你的数据连接是否设置好:1是可读;2是可写;3是可读可写
如果没有设置默认是可读
如果讲得有出入请各位大虾多指点
以上是凭我的影响写的
jacklinchen 2004-01-12
  • 打赏
  • 举报
回复
一句话:数据类型不对。字符型的要加"'"
如:
sql=sql & "'"&name & "','" & add & "','" & qq & "' ..........
qiao198 2004-01-12
  • 打赏
  • 举报
回复
老大太杂了吧
cqfeng 2004-01-12
  • 打赏
  • 举报
回复
response.write sql
response.end

看看sql有什么问题
tangss 2004-01-12
  • 打赏
  • 举报
回复
name,address,qq,email,link,title,sex,showip,ip:均为文本类型
content:备注
submittime:时间
stefli 2004-01-12
  • 打赏
  • 举报
回复
sql=sql & name & "," & add & "," & qq & "," & email & "," & links & "," & title & "," & con & ",'" & now() & "'," & sex & "," & showip & "," & ip & ")"

注意里面的类型哦。
如果是字符,就需要加'
比如:'"&email&"','"&links&"'
加载更多回复(3)

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧