update更新数据库记录时,无法获得新闻ID
我做的后台中,编辑新闻的页面,老是无法更新新闻.
编辑新闻页的文件名字是newsedit_janray.asp 处理此页的action页名字是:newsedit_janray_set.asp
newsedit_janray.asp页代码如下:
<!--#include file="conn.asp"-->
<%if session("bjxadmin")="" then
response.Write "<script language='java-script'>alert('网络超时或您还没有登陆!');window.location.href='login.asp';</script>"
response.End
end if
dim newsid
newsid=request.QueryString("newsid")
if not isnumeric(newsid) then
response.write"<script>alert(""非法访问!"");location.href=""../index.asp"";</script>"
response.end
end if
%>
<!--##############################################################################-->
<%if session("bjxadmin")="" then
response.Write "<script language='java-script'>alert('网络超时或您还没有登陆!');window.location.href='login.asp';</script>"
response.End
end if
dim newsid
newsid=request.QueryString("newsid")
if not isnumeric(newsid) then
response.write"<script>alert(""非法访问!"");location.href=""../index.asp"";</script>"
response.end
end if
%>
<!--##############################################################################-->
<html><head><title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../images/css.css" rel="stylesheet" type="text/css">
</head>
<%
sql_1="select * from BJX_news where newsid="&newsid
set rs=server.createobject("adodb.recordset")
rs.open sql_1,conn
%>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" bgcolor="#999999"><span class="STYLE1">修改新闻</span></td>
</tr>
<tr>
<td><form name="form1" method="post" action="newsedit_janray_set.asp">
<table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#999999">
<tr>
<td width="32%" align="right" bgcolor="#FFFFFF">新闻主题:</td>
<td width="68%" bgcolor="#FFFFFF"><input name="newsname" type="text" id="newsname" value="<%=rs("newsname")%>"></td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF">发 表 人:</td>
<td bgcolor="#FFFFFF"><input name="addname" type="text" id="addname" value="<%=rs("addname")%>"></td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF">新闻内容:</td>
<td bgcolor="#FFFFFF"><textarea name="newscontent" cols="55" rows="16" id="newscontent"><%=trim(rs("newscontent"))%></textarea></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF"><input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit2" value="重置"></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF"> </td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<%rs1.close
set rs1=nothing
conn.close
set conn=nothing%>
</body>
</html>
</html>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
newsedit_janray_set.asp页代码如下:
<!--#include file="conn.asp"-->
<!--#######################################-->
<%
newsid=request.Form("newsid")
newsname=server.HTMLEncode(request.form("newsname"))
addname=server.HTMLEncode(request.Form("addname"))
newscontent=server.HTMLEncode(request.form("newscontent"))
adddate=now()
'Set rs2 = Server.CreateObject("ADODB.Recordset")
'sql="select * from BJX_news where newsid="&newsid
sql="update BJX_news set newsname='"&newsname&"',addname='"&addname&"',newscontent='"&newscontent&"',adddate='"&adddate&"' where newsid='"&newsid&"'"
<!--#######################################-->
<%
newsid=request.Form("newsid")
newsname=server.HTMLEncode(request.form("newsname"))
addname=server.HTMLEncode(request.Form("addname"))
newscontent=server.HTMLEncode(request.form("newscontent"))
adddate=now()
'Set rs2 = Server.CreateObject("ADODB.Recordset")
'sql="select * from BJX_news where newsid="&newsid
sql="update BJX_news set newsname='"&newsname&"',addname='"&addname&"',newscontent='"&newscontent&"',adddate='"&adddate&"' where newsid='"&newsid&"'"
conn.execute sql
'rs2.open sql,conn,1,3
'rs2.close
'set rs2=nothing
'rs2.open sql,conn,1,3
'rs2.close
'set rs2=nothing
conn.close
set conn=nothing
response.write "<script language=java-script>alert('新闻修改成功!');window.location.href='editnews.asp';</script>"
%>
set conn=nothing
response.write "<script language=java-script>alert('新闻修改成功!');window.location.href='editnews.asp';</script>"
%>
<!--
'rs.addnew
rs2("newsname")=newsname
rs2("addname")=addname
rs2("newscontent")=newscontent
rs2("adddate")=adddate
rs2.update
rs2("newsname")=newsname
rs2("addname")=addname
rs2("newscontent")=newscontent
rs2("adddate")=adddate
rs2.update
%-->
'看,我用rs2.update也无法更新.如果我把上面的sql语句:sql="select * from BJX_news where newsid="&newsid
改成: sql="select * from BJX_news
可以更新,不过因为没有查询特定的记录,只能更新第一条记录.
我总结的问题是action页无法获得提交表单页的新闻id ,即newsid
但是我解决不了,还是麻烦各位高手了.