为什么不能向数据库中添加数据?
做一个新闻发布系统,添加页面不能向数据库中加数据,请大家帮我看一下。
access数据库
表:tbl_news
字段及数据类型:
ID 自动编号
title 文本
content 备注
sourcefile 文本 (出处)
reship 文本 (转载)
/----------------------------
addnews.asp (纯html文件)
<HTML>
<HEAD>
<TITLE> 新闻添加</TITLE>
</HEAD>
<BODY>
<CENTER>
<p><FONT SIZE=3 COLOR="blue"><B>添加新闻</B></FONT></p>
<hr>
<p>
<form method=POST action="addresult.asp">
<table>
<tr>
<td align=right>新闻标题</td>
<td>
<input type="text" name="txttitle" size="72">
</td>
</tr>
<tr>
<td align=right>新闻内容</td>
<td>
<textarea name="txtcnt" rows="15" cols="70"></textarea>
</td>
</tr>
<tr>
<td align=right>出处</td>
<td>
<input type="text" name="txtsf">
</td>
</tr>
<tr>
<td align=right>转载</td>
<td>
<input type="text" name="txtrsh">
</td>
</tr>
<tr>
<td align=right>
<input type="submit" value="添加新闻" name="submit">
</td>
<td>
<input type="reset" name="reset">
</td>
</tr>
</table>
</form>
</CENTER></BODY>
</HTML>
/----------------------------------------------
添加结果页面addresult.asp :
<!--#include file="cndb.asp"-->
<%
data=" '"&request("txttitle")&"','"&request("txtcnt")&_
"','"&request("txtsf")&"','"&request("txtrsh")&_
"','"&now&"' "
set rs=server.createobject("adodb.recordset")
sql="insert into tbl_news(title,content,sourcefile,reship,time) values("&data&")"
cn.execute(sql)
%>
<html>
<head>
<title>添加成功</title>
</head>
<body>
添加成功!
<a href="addnews.asp">返回</a>
</body>
</html>
<%rs.close
cn.close
%>
/----------------------
cndb.asp的代码:(这个文件是没问题的,用在删除页面中是好的)
DbPath = SERVER.MapPath("WebCenter.mdb")
Set cn = Server.CreateObject("ADODB.Connection")
cn.open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DbPath
/-----------------------------------------------------------------
IE说insert into语句有问题,又说"cn.execute(sql)" 这句有问题,我觉得没有,大家帮忙看一下。