急救。。。。asp无法与数据库建立连接

wps110 2005-04-14 02:19:39
表单上的信息无法写入数据库,程序如下:(数据库用的是ACCESS)


<%
set Con = Server.CreateObject("ADODB.Connection")
Con.Open = "DRIVER = {Microsoft Access Driver(*.mdb)};DBQ = "+ server.MapPath("BookStore.mdb")

action=trim(Request("action")) //trim是什么意思?
Poster=trim(Request("Poster"))
Title=trim(Request("Title"))
Content=trim(Request("Content"))

if action="post" then checkpass=true
if len(poster)<1 then checkpass=false
if len(Title)<1 then checkpass=false
if len(Content)<1 then checkpass=false
if checkpass then

query="insert into GuestBook (Poster,"
query=query+"Title,"
query=query+"Content) values('"
query=query+Poster+"','"
query=query+Title+"','"
query=query+Content+"')"

Con.Execute query

Response.Redirect"guestbook.asp"
end if
%>

<html>
<head>
<title>发布留言</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form name="form1" method="post" action="gbpost.asp">
<input typwe="hidden" name="action" value="post">
<p> </p>
<table width="600" border="1" cellspacing="0" cellpadding="1">
<tr>
<td width="93">留言者</td>
<td width="497"><input type="text" name="Poster" id="Poster">*</td>
</tr>
<tr>
<td>主题</td>
<td><input type="text" name="Title" id="Title"></td>
</tr>
<tr>
<td height="18">内容</td>
<td><textarea name="Content" id="Content" ></textarea>*</td>
</tr>
<tr>
<td>操作</td>
<td><input type="submit" name="Submit" value="提交">
<input type="reset" name="Reset" id="Reset" value="重填"></td>
</tr>
</table>
</form>
</body>
</html>
...全文
107 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
yb2008 2005-04-14
  • 打赏
  • 举报
回复
trim是删除字符串两边的空格
yuanl 2005-04-14
  • 打赏
  • 举报
回复
connstr="DBQ="+server.mappath(".../..../WWWWW.asp")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
menrock 2005-04-14
  • 打赏
  • 举报
回复
文本框里面写着“post”字串,如果给楼主改了,那就无法插入数据库了
menrock 2005-04-14
  • 打赏
  • 举报
回复
<input typwe="hidden" name="action" value="post">,type多了个w,这样输出的话,这个hidden会变成一个文本框
wps110 2005-04-14
  • 打赏
  • 举报
回复
请问yuanl(鹰):这样写了之后,其它的不变吗?
zhaoliangpat 2005-04-14
  • 打赏
  • 举报
回复
先 response.write query 看看什么结果!!

建议用
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("example3.mdb")

name=request.form("name")
tel=request.form("tel")
message=request.form("message")
set rs=server.createobject("adodb.recordset")
exec="insert into guestbook(name,tel,message)values(\'"+name+"\',"+tel+",\'"+message+"\')"
rs.open sql,conn,1,3
conn.close
set conn=nothing
response.write "记录添加成功!"
%>
menrock 2005-04-14
  • 打赏
  • 举报
回复
if checkpass then是可以的,对布尔型变量可以这样写
abcdefg3305 2005-04-14
  • 打赏
  • 举报
回复
Trim()就是去提字符串左右两边的空格。
menrock 2005-04-14
  • 打赏
  • 举报
回复
出错信息是什么?
yuanl 2005-04-14
  • 打赏
  • 举报
回复
query="insert into GuestBook(Poster,Title,Content) values('"&Poster&"','"&Title&"','"&Content&"')"
wps110 2005-04-14
  • 打赏
  • 举报
回复
加上了if checkpass=true then 提示这样的错误:

错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序
underone 2005-04-14
  • 打赏
  • 举报
回复
if checkpass then
checkpass等于什么啊
其运算结果是 True 或 False
underone 2005-04-14
  • 打赏
  • 举报
回复
LTrim、RTrim 和 Trim 函数
请参阅
Left 函数 | Right 函数
要求
版本 1
返回不带前导空格 (LTrim)、后续空格 (RTrim) 或前导与后续空格 (Trim) 的字符串副本。

LTrim(string)
RTrim(string)
Trim(string)
string 参数是任意有效的字符串表达式。如果 string 参数中包含 Null,则返回 Null。

说明
下面的示例利用 LTrim, RTrim, 和 Trim 函数分别用来除去字符串开始的空格、尾部空格、 开始和尾部空格:

Dim MyVar
MyVar = LTrim(" vbscript ") 'MyVar 包含 "vbscript "。
MyVar = RTrim(" vbscript ") 'MyVar 包含 " vbscript"。
MyVar = Trim(" vbscript ") 'MyVar 包含 "vbscript"。
abcdefg3305 2005-04-14
  • 打赏
  • 举报
回复
if checkpass=true then
abcdefg3305 2005-04-14
  • 打赏
  • 举报
回复
if checkpass then

query="insert into GuestBook (Poster,"
query=query+"Title,"
query=query+"Content) values('"
query=query+Poster+"','"
query=query+Title+"','"
query=query+Content+"')"

Con.Execute query

Response.Redirect"guestbook.asp"
end if
中的if checkpass then缺少判断杀件了吧,

28,406

社区成员

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

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