修改一条数据问题

zigine 2003-11-19 09:30:12
修改一条数据问题,不懂这样写对不对,我提交后,出错,内部出错,不懂为什么,是不是语法用错了?
要用execute 还是用updata来呢?
<!--#include file="conn.asp"-->
<!--#include file="check_login.asp"-->
<link href="css.css" rel="stylesheet" type="text/css">
<%
dim id
id=request.QueryString("id")
if request.QueryString("action")="save" then
conn.execute "update news set theme='"&theme&"',content='"&content&"',link='"&link&"' where id=" & id
response.write "<script language=javascript>alert('更改成功!');history.go(-1);</script>"
response.End
end if
%>
<%
id=request("id")
set rs=server.createobject("ADODB.Recordset")
sql="select * from news where id=" & id
rs.open sql,conn,1,1
%>
<table cellspacing=0 cellpadding=0 width="100%" border=0>
<tbody>
<tr>
<td valign=center>  <img src="images/doc.gif" width="9" height="9">
<font color="#0066cc">当前位置→站内新闻→添加新闻</font></td>
</tr>
<tr>
<td valign=center height="200" align="center">
<table width="400" border="0" cellspacing="4" cellpadding="0">
<form name="form1" method="post" action="modify_news.asp">
<tr>
<td>标题:
<input type="text" name="theme" size="40" class="input" value=<%=trim(rs("theme"))%>> </td>
</tr>
<tr>
<td>链接:
<input name="link" type="text" class="input" size="40"value=<%=rs("link")%>></td>
</tr>
<tr>
<td>時间:
<input type="text" name="time" size="40" class="input" value=<%=rs("time")%>>
</td>
</tr>
<tr>
<td> <textarea name="content" cols="56" rows="14" style="font-family: '宋体'; font-size: 9pt; border: thin #FFFFFF groove; background-color: #DAEFFC" ><%=rs("content")%></textarea>
</td>
</tr>
<tr>
<td align="center"><input type="submit" name="bb" value="修改" class="input">
    
<input type="reset" name="bb2" value="重写" class="input">
<input type="hidden" name="action" value="save">
<input type="hidden" name="id" value="<%=rs("id")%>">
<input type="hidden" name="theme" value="<%=rs("theme")%>">
<input type="hidden" name="content" value="<%=rs("content")%>">
<input type="hidden" name="link" value="<%=rs("link")%>">
</td>
</tr>
</form>
</table>
</td>
</tr>
</tbody>
</table>
...全文
32 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
wsmall 2003-11-19
  • 打赏
  • 举报
回复
你把sql语句单独输出来看看
zhang_luo 2003-11-19
  • 打赏
  • 举报
回复
不用搞的那么复杂吧,你直接用update ……where id="&id不就得了
zigine 2003-11-19
  • 打赏
  • 举报
回复
还是不行!
dim id
id=request.QueryString("id")
在这里还有id的值
if request.QueryString("action")="save" then
到了这里没了!是不是用了两个querystring?
zigine 2003-11-19
  • 打赏
  • 举报
回复
rs.open "select * from news ",conn,1,3
是不是这个,没有where id?:(
zigine 2003-11-19
  • 打赏
  • 举报
回复
我用updata可以提交成功,但是,他怎么多出一条数据来呢?哪儿写错了?
bzscs 2003-11-19
  • 打赏
  • 举报
回复
既然没显示出错,你怎么知道出错了呢?

试试这个
conn.execute "update news set theme='"&theme&"',content='"&content&"',link='"&link&"' where [id]=" & id
zigine 2003-11-19
  • 打赏
  • 举报
回复
id有值呀,不懂哪儿错了。
lovehwq21 2003-11-19
  • 打赏
  • 举报
回复
估计是你的id没值,也就是where条件出错
dim id
id=request.QueryString("id")
Response.write "|" & id & "|"
Response.end
看看有没有东西
DeltaCat 2003-11-19
  • 打赏
  • 举报
回复
建议你采用这种方法,不要用
conn.Execute "update...."
容易出错
zigine 2003-11-19
  • 打赏
  • 举报
回复
提交后,出错,没显示出哪错了?下面这个是添加数据的那个,一样的写,会多出一条数据来,要怎么做?
<!--#include file="conn.asp"-->
<!--#include file="check_login.asp"-->
<link href="css.css" rel="stylesheet" type="text/css">

<%
dim id,rs
id=request.QueryString("id")
if request.QueryString("action")="save" then
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from news ",conn,1,3
rs.addnew
rs("theme")=trim(request("theme"))
rs("content")=request("content")
rs("link")=trim(request("link"))
rs("time")=trim(request("time"))
rs("hit")=0
rs.update

response.write "<script language=javascript>alert('更改成功!');history.go(-1);</script>"
response.End
end if
%>

<%set rs=server.CreateObject("adodb.recordset")
rs.open "select * from news where id="&id,conn,1,1%>
<table cellspacing=0 cellpadding=0 width="100%" border=0>
<tbody>
<tr>
<td valign=center>  <img src="images/doc.gif" width="9" height="9">
<font color="#0066cc">当前位置→站内新闻→添加新闻</font></td>
</tr>
<tr>
<td valign=center height="200" align="center">
<table width="400" border="0" cellspacing="4" cellpadding="0">
<form name="form1" method="post" action="modify_news.asp?action=save">
<tr>
<td>标题:
<input type="text" name="theme" size="40" class="input" value=<%=trim(rs("theme"))%>> </td>
</tr>
<tr>
<td>链接:
<input name="link" type="text" class="input" size="40"value=<%=rs("link")%>></td>
</tr>
<tr>
<td>時间:
<input type="text" name="time" size="40" class="input" value=<%=rs("time")%>>
</td>
</tr>
<tr>
<td> <textarea name="content" cols="56" rows="14" style="font-family: '宋体'; font-size: 9pt; border: thin #FFFFFF groove; background-color: #DAEFFC" ><%=rs("content")%></textarea>
</td>
</tr>
<tr>
<td align="center"><input type="submit" name="bb" value="修改" class="input">
    
<input type="reset" name="bb2" value="重写" class="input">
<input type="hidden" name="action" value="save"></td>
</tr>
</form>
</table>
</td>
</tr>
</tbody>
</table><%rs.close
set rs=nothing%>
popcode 2003-11-19
  • 打赏
  • 举报
回复
错误信息是什么?
zigine 2003-11-19
  • 打赏
  • 举报
回复
唉,原来,就这么写就行了update就可以了我还跑了那么多的路,晕
<%
if request("bb")="修改" then
sql="update news set theme='"&request("theme")&"',link='"&request("link")&"',content='"&request("content")&"' where id="&request("id")
conn.execute(sql)
response.write "<script language=javascript>alert('更改成功!');history.go(-1);</script>"

%>
dafei0320 2003-11-19
  • 打赏
  • 举报
回复
对了太复杂了
这个问题就直接
update ……where id="&id
bzscs 2003-11-19
  • 打赏
  • 举报
回复
楼主的问题很多呀,首先modify_news.asp页面中的form就有问题,怎么有三个同名的隐藏域:<input type="hidden" name="theme" value="<%=rs("theme")%>">
<input type="hidden" name="content" value="<%=rs("content")%>">
<input type="hidden" name="link" value="<%=rs("link")%>">

其次组成sql语句的时候,没有获取传递过来的值啊:把theme=request.form("theme"),content=request.form("content"),link=request.form("link")加上

28,390

社区成员

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

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