动态修改数据库的问题,请大家帮慢

newqq 2008-09-10 09:50:11
小生第一次用asp写程序,现在遇到一个问题,请大家帮忙,
我要做的是列出一个标的记录,每条记录旁边动态生成一个text,然后后点击提交按钮,将表中一个字段的值修改成text的值,
以下是我写的,在while 和 wend 之间加入<input name="<%=rs("id")%>" type="text" size="10" >,text名字用字段的id来命名,
<form action="updatetoubiao.asp?&active=save"
method="get" name="reply" id="reply" onSubmit="return CheckForm();">
以下是我的updatetoubiao
<%

For Each item in request.form
if item>0 then
if request("active")="save" then
'conn.execute("delete from [User] where id="&item )
conn.execute("update reply set iprice='"&request.Form("id")&"' where id='"&request.Form("id")&"'")
end if
end if
Next
response.write "<script language=javascript>"
response.write"alert('修改成功!');"

response.write "</script>"

%>
这个是我看了一点资料写的,写的不对,点了提交不起作用,请高手指点,谢谢。
...全文
133 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
newqq 2008-09-10
  • 打赏
  • 举报
回复
感谢大家,特别感谢luxu001207 ,谢谢,结贴
蓝色木 2008-09-10
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 haozi678 的回复:]
For Each item in request.form
conn.execute("update reply set iprice='"&request.Form("id")&"' where id='"&request.Form("id")&"'")

request.Form("id")改成request.Form(item)
[/Quote]
Atai-Lu 2008-09-10
  • 打赏
  • 举报
回复
<form/>标记都没有...
  • 打赏
  • 举报
回复
哎,我不说了

request.Form("id")你这个根本就没有值

而且id='"&request.Form("id")&"
就不应该是等于这个
蓝色木 2008-09-10
  • 打赏
  • 举报
回复
For Each item in request.form
conn.execute("update reply set iprice='"&request.Form("id")&"' where id='"&request.Form("id")&"'")

request.Form("id")改成request.Form(item)
newqq 2008-09-10
  • 打赏
  • 举报
回复
我打开跟踪器,都没跟踪到sql,说明sql没有执行,是哪里出问题了呢
gingerkang 2008-09-10
  • 打赏
  • 举报
回复
表单中的id应该不止一个吧


估计应该是这样的

<%
if request("active")="save" then
for i=1 to request.form("id").count
conn.execute("update reply set iprice='"& Replace(request.Form(request.Form("id")(i)),"'","''") &"' where id="& CInt(request.Form("id")(i)) &"")
next
response.write " <script language=javascript>"
response.write"alert('修改成功!');"
response.write " </script>"
end if
%>
Atai-Lu 2008-09-10
  • 打赏
  • 举报
回复

iprice='"&request.Form("id")&"' where id='"&request.Form("id")&"'
//两个request.Form("id")都是有问题的
newqq 2008-09-10
  • 打赏
  • 举报
回复
修改页面
<%
if request("active")="save" then
For Each item in request.form
if item>0 then
'conn.execute("delete from [User] where id="&item )
conn.execute("update reply set iprice='"&request.Form("id")&"' where id='"&request.Form("id")&"'")
end if
Next
end if
response.write " <script language=javascript>"
response.write"alert('修改成功!');"
response.write " </script>"
%>
newqq 2008-09-10
  • 打赏
  • 举报
回复
一下是所有代码
第一个页面
<!--#include file="const.asp"-->
<!--#include file="path.asp"-->
<!--#include file="IsUser.asp"-->
<%
'aaa=request.Form("aaa")
'set rs=conn.execute("select * from Topic where typeid="&request("typeid")&" and topic='"&aaa&"'")
set rs=conn.execute("select * from Topic where typeid="&request("typeid")&"")
%>

<HTML><HEAD><TITLE><%=WebTitle%></TITLE>
<SCRIPT language=JavaScript>

function CheckForm()
{
if (document.reply.endtime<now() 0) {
alert("此次招标已经结束.");
document.reply.qty.focus();
return false;
}


return true;
}
</SCRIPT>

<META http-equiv=Content-Type content="text/html; charset=gb2312"><LINK
href="styles.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<style type="text/css">
<!--
.STYLE2 {font-size: 14px}
.STYLE7 {color: #8000FF}
.STYLE9 {
font-size: 11pt;
color: #295E17;
}
-->
</style>
</HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0>
<P>
<table width="851"
border=1 align=left cellpadding=2 cellspacing=0 bordercolor="#D1E9ED" bgcolor=#FFFFFF>
<!--DWLayoutTable-->
<tbody>
<form action="updatetoubiao.asp?&active=save"
method="get" name="reply" id="reply" onSubmit="return CheckForm();">
<tr bgcolor=#ffffff>
<td height="18" colspan=7 background="images/banner/002.jpg"><p align="center">招标详情</p></td>
</tr>

<%
if not (rs.bof or rs.eof) then '如果所查询的数据不为空
%>
<tr align=center bgcolor=#BFD3EE>
<td height="1" colspan="5" align="left" bgcolor="#FFFFFF" class="STYLE2"><span class="STYLE2" style="BORDER-RIGHT: #FFFFFF 1px solid; BORDER-LEFT: #FFFFFF 1px solid;BORDER-Bottom: #FFFFFF 1px solid"></span><span class="STYLE2" style="BORDER-RIGHT: #FFFFFF 1px solid; BORDER-LEFT: #FFFFFF 1px solid;BORDER-Bottom: #FFFFFF 1px solid"><span class="STYLE2" style="BORDER-RIGHT:#FFFFFF 1px solid; BORDER-LEFT: #FFFFFF 1px solid;BORDER-Bottom: #FFFFFF 1px solid">项目名称:  </span></span><span class="STYLE2" style="BORDER-RIGHT: #FFFFFF 1px solid; BORDER-LEFT: #FFFFFF 1px solid;BORDER-Bottom: #FFFFFF 1px solid"><%=rs("topic")%><span style="BORDER-RIGHT:#FFFFFF 1px solid; BORDER-LEFT: #FFFFFF 1px solid;BORDER-Bottom: #FFFFFF 1px solid">招标开始时间:<span style="BORDER-RIGHT: #FFFFFF 1px solid; BORDER-LEFT: #FFFFFF 1px solid;BORDER-Bottom:#FFFFFF 1px solid"><%=rs("starttime")%><span class="STYLE2" style="BORDER-RIGHT: #FFFFFF 1px solid; BORDER-LEFT: #FFFFFF 1px solid;BORDER-Bottom: #FFFFFF 1px solid">招标结束时间:<span class="STYLE2" style="BORDER-RIGHT: #FFFFFF 1px solid; BORDER-LEFT: #FFFFFF 1px solid;BORDER-Bottom: #FFFFFF 1px solid"><span class="STYLE2" style="BORDER-RIGHT: #FFFFFF 1px solid; BORDER-LEFT:#FFFFFF 1px solid;BORDER-Bottom: #FFFFFF 1px solid"><%=rs("endtime")%>交货日期:<font color=red class="STYLE9"><strong><%=rs("finish_time")%></strong></font></span></span></span></span></span></span></td>
</tr>
<tr align=center bgcolor=#BFD3EE>
<td width="152" height="21" align="left" bgcolor="#FFFFFF" ><div align="center"><span class="STYLE9">物料编码</span></div></td>
<td width="248" align="left" bgcolor="#FFFFFF" class="wordorange"><div align="center" class="STYLE9">物料名称</div></td>
<td width="239" align="left" bgcolor="#FFFFFF" class="wordorange"><div align="center" class="STYLE9">规格尺寸</div></td>
<td width="120" align="left" bgcolor="#FFFFFF" class="STYLE2"><div align="center"><span class="STYLE9" style="BORDER-RIGHT: #FFFFFF 1px solid; BORDER-LEFT: #FFFFFF 1px solid;BORDER-Bottom: #FFFFFF 1px solid">招标数量</span></div></td>
<td width="60" height="21" align="left" bgcolor="#FFFFFF" class="STYLE2"><div align="center" class="STYLE9">投标单价</div></td>
</tr>
<%while not rs.eof%>
<tr align=center bgcolor=#BFD3EE>
<td align="left" bgcolor="#FFFFFF" class="STYLE2"><span class="STYLE7" style="BORDER-RIGHT: #FFFFFF 1px solid; BORDER-LEFT: #FFFFFF 1px solid;BORDER-Bottom: #FFFFFF 1px solid"> <%=rs("ccode")%></span></td>
<td align="left" bgcolor="#FFFFFF" ><font color=red class="STYLE7"><%=rs("code_name")%></font></td>
<td align="left" bgcolor="#FFFFFF"><font color=red class="STYLE7"><%=rs("code_size")%><input type="hidden" name="id" value="<%=rs("id")%>"></font></td>
<td align="left" bgcolor="#FFFFFF" ><span style="BORDER-RIGHT: #FFFFFF 1px solid; BORDER-LEFT: #FFFFFF 1px solid;BORDER-Bottom: #FFFFFF 1px solid"><font color=red></font></span><span class="STYLE7" style="BORDER-RIGHT: #FFFFFF 1px solid; BORDER-LEFT: #FFFFFF 1px solid;BORDER-Bottom: #FFFFFF 1px solid"><%=rs("qty")%> <%=rs("unit")%></span></td>
<td align="left" bgcolor="#FFFFFF" > 
<input name="<%=rs("id")%>" type="text" size="10" ></td>
</tr>
<%
response.Write("")
rs.movenext
wend
%>

<%
end if
%>

<tr bgcolor=#ffffff>
<td
style="BORDER-RIGHT: #BFD3EE 1px solid; BORDER-LEFT: #BFD3EE 1px solid"
colspan=7><div align=center>
<table width="381" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="158" scope="row"> <a href="javascript:history.go(-1);">返回</a></th>
<th width="223" scope="row"><input name="提交" type="submit" value="确定投标">
 </th>
</tr>
</table>
</div></td>
</tr>
</tbody>
</table>
<P></P>
</BODY></HTML>

newqq 2008-09-10
  • 打赏
  • 举报
回复
谢谢各位,不过问题还没解决,还是修改不了
  • 打赏
  • 举报
回复
晕死,你们都说的什么东西啊???

根本说不到重点上去

For Each item in request.form
if item>0 then
if request("active")="save" then
'conn.execute("delete from [User] where id="&item )
conn.execute("update reply set iprice='"&request.Form("id")&"' where id='"&request.Form("id")&"'")
end if
end if
Next
response.write " <script language=javascript>"
response.write"alert('修改成功!');"

response.write " </script>"

你红色部分明显错误

request.Form("id")是文本框的值,不是你id的值,难道你的ID和iprice的值是相等一样的???
蓝色木 2008-09-10
  • 打赏
  • 举报
回复
11楼说的也很对
确保CheckForm();函数能正常返回true
mmidd 2008-09-10
  • 打赏
  • 举报
回复
VBScript code
<%
if request("active")="save" then
For Each item in request.form
if item>0 then
'conn.execute("delete from [User] where id="&item )
conn.execute("update reply set iprice='"&request.Form("id")&"' where id='"&request.Form("id")&"'")
end if
Next
end if
response.write " <script language=javascript>"
response.write"alert('修改成功!');"
response.write " </script>"
%>
[/Quote]
确保CheckForm();函数能正常返回true
jhwcd 2008-09-10
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 g125989100 的回复:]
VBScript code<%
if request("active")="save" then
For Each item in request.form
if item>0 then
'conn.execute("delete from [User] where id="&item )
conn.execute("update reply set iprice='"&request.Form("id")&"' where id='"&request.Form("id")&"'")
end if
Next
end if
response.write " <script language=javascript>"
response.write"alert('修改成功!');"
response.write " </script>" …
[/Quote]
就类似7楼的写法吧,楼主最好把完整代码贴出来看看。
蓝色木 2008-09-10
  • 打赏
  • 举报
回复
补充 Request.Form(item)
蓝色木 2008-09-10
  • 打赏
  • 举报
回复
<input name=" <%=rs("id")%>" type="text" size="10" >

request.Form("id")是取得的上边这个name吗
如果是的话你肯定取不到
For Each item in request.form

就用item操作就行了
不耐烦 2008-09-10
  • 打赏
  • 举报
回复
<% 
if request("active")="save" then
For Each item in request.form
if item>0 then
'conn.execute("delete from [User] where id="&item )
conn.execute("update reply set iprice='"&request.Form("id")&"' where id='"&request.Form("id")&"'")
end if
Next
end if
response.write " <script language=javascript>"
response.write"alert('修改成功!');"
response.write " </script>"
%>
Atai-Lu 2008-09-10
  • 打赏
  • 举报
回复
晕啊!
不是叫你把判断都去掉啊...
把你全部代码贴上来
newqq 2008-09-10
  • 打赏
  • 举报
回复
。。
加载更多回复(4)

28,391

社区成员

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

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