ASP添加记录问题
数据库表ziduan里的z_name里的记录对应表tongji里的字段.----------------index.asp-------------<FORMlangua...
数据库表ziduan里的z_name里的记录对应表tongji里的字段.
----------------index.asp-------------
<FORM language=javascript name=Form1 onsubmit="return form1_onsubmit()" action=save.asp?act=save method=post> <table width="500" border="0" align="center" cellpadding="0" cellspacing="0"> <%set rsu=conn.execute("select * from [ziduan] order by Z_id ") if not rsu.eof then do while not rsu.eof %> <tr> <td align="right"><%=rsu("Z_mingcheng")%>:</td> <td align="center"><input name="<%=rsu("Z_name")%>" type="text" size="50"></td> <td align="left"><%=rsu("Z_beizhu")%></td> </tr> <% rsu.movenext loop end if rsu.close set rsu=nothing %>
<tr> <td colspan="3" align="center"> <input type="submit" name="Submit" value="确 定" /> <input type="reset" name="Submit2" value="重 填" /> </td> </tr> </table>
</form>-----------------save.asp-------------------
<%
if Request.QueryString("act")="save" then set rs=server.createobject("adodb.recordset") sql="select * from tongji" rs.open sql,conn,1,3 rs.addnew set rsu=conn.execute("select * from ziduan order by Z_id ") if not rsu.eof then do while not rsu.eof rs(rsu("Z_name"))=Trim(Request.Form(rsu("Z_name"))) rsu.movenext loop end if rsu.close set rsu=nothing
rs.update rs.close set rs=nothing response.write ("<script>alert('恭喜您,信息添加成功!');window.location.replace('index.asp');</script>")end if%>
问一下添加到数据库的记录为什么是空记录呢,如果代码这样写不行,该如何写来实现这个动态功能? 展开
----------------index.asp-------------
<FORM language=javascript name=Form1 onsubmit="return form1_onsubmit()" action=save.asp?act=save method=post> <table width="500" border="0" align="center" cellpadding="0" cellspacing="0"> <%set rsu=conn.execute("select * from [ziduan] order by Z_id ") if not rsu.eof then do while not rsu.eof %> <tr> <td align="right"><%=rsu("Z_mingcheng")%>:</td> <td align="center"><input name="<%=rsu("Z_name")%>" type="text" size="50"></td> <td align="left"><%=rsu("Z_beizhu")%></td> </tr> <% rsu.movenext loop end if rsu.close set rsu=nothing %>
<tr> <td colspan="3" align="center"> <input type="submit" name="Submit" value="确 定" /> <input type="reset" name="Submit2" value="重 填" /> </td> </tr> </table>
</form>-----------------save.asp-------------------
<%
if Request.QueryString("act")="save" then set rs=server.createobject("adodb.recordset") sql="select * from tongji" rs.open sql,conn,1,3 rs.addnew set rsu=conn.execute("select * from ziduan order by Z_id ") if not rsu.eof then do while not rsu.eof rs(rsu("Z_name"))=Trim(Request.Form(rsu("Z_name"))) rsu.movenext loop end if rsu.close set rsu=nothing
rs.update rs.close set rs=nothing response.write ("<script>alert('恭喜您,信息添加成功!');window.location.replace('index.asp');</script>")end if%>
问一下添加到数据库的记录为什么是空记录呢,如果代码这样写不行,该如何写来实现这个动态功能? 展开
展开全部
<input name="<%=rsu("Z_name")%>" type="text" size="50">
应该是
<input name="Z_name" value="<%=rsu("Z_name")%>" type="text" size="50">
-----------------save.asp-------------------
<%
if Request.QueryString("act")="save" then
set rs=server.createobject("adodb.recordset")
if not Isnull(Trim(request.form("Z_name"))) Then
Z_name=Trim(request.form("Z_name"))
Z_name1=split(Z_name,",")
for i=0 to ubound(Z_name1)
sql="select * from tongji"
rs.open sql,conn,1,3
rs.addnew
rs("Z_name")=Z_name1(i)
rs.update
rs.close
Next
set rs=nothing
response.write ("<script>alert('恭喜您,信息添加成功!');window.location.replace('index.asp');</script>")
response.end
end if %>
应该是
<input name="Z_name" value="<%=rsu("Z_name")%>" type="text" size="50">
-----------------save.asp-------------------
<%
if Request.QueryString("act")="save" then
set rs=server.createobject("adodb.recordset")
if not Isnull(Trim(request.form("Z_name"))) Then
Z_name=Trim(request.form("Z_name"))
Z_name1=split(Z_name,",")
for i=0 to ubound(Z_name1)
sql="select * from tongji"
rs.open sql,conn,1,3
rs.addnew
rs("Z_name")=Z_name1(i)
rs.update
rs.close
Next
set rs=nothing
response.write ("<script>alert('恭喜您,信息添加成功!');window.location.replace('index.asp');</script>")
response.end
end if %>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
从你的代码上看,逻辑和编写都没有错,应该是掉值了,ASP很容易出现这种情况
set rsu=conn.execute("select * from ziduan order by Z_id ")
if not rsu.eof then
do while not rsu.eof
rs(rsu("Z_name"))=Trim(Request.Form(rsu("Z_name")))
rsu.movenext
loop
end if
rsu.close
set rsu=nothing
改成
set rsu=conn.execute("select * from ziduan order by Z_id ")
do while not rsu.eof
z_name=rsu("Z_name")
'如果还是没有值,将以下两句注释去掉,断点调试一下z_name 是否有值出来
'Response.Write z_name
'Response.End
rs(z_name)=Trim(Request.Form(z_name))
rsu.movenext
loop
rsu.close
set rsu=nothing
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
第一 从上图中可以看到,Id是有值的,后面的所有字段是空的,说明insert本身是没有问题的
请您检查一下,您的insert 中的values 中,是否有值,也就是说,insert 之前有值?
或者alert 你将要insert的字段的值,是否获取到呢
请您检查一下,您的insert 中的values 中,是否有值,也就是说,insert 之前有值?
或者alert 你将要insert的字段的值,是否获取到呢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询