添加记录出现的问题,实在找不出哪里不对,高手帮忙看一下
这个问题困扰我很久了。
。 <%@LANGUAGE= "VBSCRIPT " CODEPAGE= "936 "%>
<!--#include file= "conn/conn.asp "-->
<% dim title_pic,lujin_pic,ps
if request( "title_pic ")= " " then
title_pic= "1111111111 "
else
title_pic=trim(left(request( "title_pic "),10))
end if %>
<%if request( "picture ")= " " then
lujin_pic= "111111111 "
else
lujin_pic=trim(request( "picture "))
end if %>
<% If request( "textarea ")= " " Then
ps= "111111111111 "
else
ps=request( "textarea ")
end if%>
<%set rs2=Server.CreateObject( "adodb.recordset ")
sql2= "select * from pic where(id is null ) "
rs2.open sql2,conn,1,3
rs2.addnew
rs2( "lujin ")=lujin_pic
rs2( "uptime ")=date()
rs2( "title ")=title_pic
rs2( "filename ")=photofold
rs2( "shuoming ")=ps
rs2.update%>
<%= ps %>
<%= title_pic %>
<%= date() %>
<%= lujin_pic %>
<%rs2.close
set rs2=nothing
%> <script language= "javascript "> alert( "记录添加成功!! ") </script>
经测试传递的值都没问题,可就是添加不了记录。
conn.asp代码如下:
<%dim conn,connstr
on error resume next
set conn=server.CreateObject( "adodb.connection ")
connstr = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ= " & Server.MapPath( "/datasource/login.mdb ")
conn.open connstr
%>
也试着把。1,3等改成3,3可还是不成功。
------解决方案--------------------select * from pic where(id is null )
先改成
select * from pic
再检测是否有空值.
或将数据库各个字段设置充许为空
再检测获取的各个值是否包含 '
如果有,就过滤掉.
还有,是不是添加了,你没有刷新页面,所以没看到最新结果?(这个小错误不会犯吧)
------解决方案-------------------- <%set rs2=Server.CreateObject( "adodb.recordset ")
sql2= "select * from pic where(id is null ) "
rs2.open sql2,conn,1,3
rs2.addnew
rs2( "lujin ")=lujin_pic
rs2( "uptime ")=date()
rs2( "title ")=title_pic
rs2( "filename ")=photofold
rs2( "shuoming ")=ps
rs2.update%>
<%= ps %>
<%= title_pic %>
<%= date() %>
<%= lujin_pic %>
<%rs2.close
set rs2=nothing
%> <script language= "javascript "> alert( "记录添加成功!! ") </script>
改成
<%
dim sql
sql= "insert into pic(lujin,uptime,title,filename,shuoming) values( ' " & lujin_pic & " ',date(), ' " & title_pic & " ', ' " & photofold & " ', ' " & ps & " ') "
conn.execute(sql