
ASP代码改错 一共有三个页面,list.asp页面是用来显示数据库中所有记录的。还有一个删除页面,一个修改页
list.asp<%o2=request("o2")setrs=Server.CreateObject("adodb.recordset")dimsqlsql="sele...
list.asp
<%
o2=request("o2")
set rs=Server.CreateObject("adodb.recordset")
dim sql
sql="select * from acc where zth='01' and o1='ztlb'"
rs.open sql,conn,1,3
Response.Write("<table><tr><td width=60>编码</td><td width=120>名称(简体)</td><td width=120>名称(繁体)</td><td width=120>名称(英文)</td><td width=150>操作</td></tr>")
rs.movefirst
while not rs.eof
Response.Write("<tr><td > ")
Response.Write(rs("o2"))
Response.Write("</td><td >")
Response.Write(rs("lmc1"))
Response.Write("</td><td>")
Response.Write(rs("lmc2"))
Response.Write("</td><td >")
Response.Write(rs("lmc3"))
Response.Write("</td>")
%><td ><a href="update1.asp?o2=<%=rs("o2")%>">修改</a>
<a href='javascript:if(confirm("您确认要删除该条记录吗?"))location="delete.asp?o2=<%=rs("o2")%>"'>删除</a></td>
<%
rs.movenext
wend
Response.Write("</tr></table>")
rs.close
conn.close
set rs=nothing
set conn=nothing
%>
add1.asp
<%
bianma=Request("bianma" )
mingyi=Request("mingyi" )
minger=Request("minger" )
mingsan=Request("mingsan" )
set rs=Server.CreateObject("adodb.recordset")
dim sql
sql="select * from acc where zth='01' and o1='ztlb'"
rs.open sql,conn,1,3
rs.addnew()
rs("zth")="01"
rs("o1")="ztlb"
rs("o2")=bianma
rs("lmc1")=mingyi
rs("lmc2")=minger
rs("lmc3")=mingsan
rs.update()
response.Redirect("list.asp")
rs.close
conn.close
set rs=nothing
set conn=nothing
%>
update.asp
<%
set rs=Server.CreateObject("adodb.recordset")
dim sql,rs
o2=Trim(Request.QueryString("o2"))
sql="select * from azz where zth='01'and o1 ='ztlb' and o2='"&o2 & "'"
rs.open sql,conn,1,3
bianma=rs("o1")
mingyi=rs("lmc1")
minger=rs("lmc2")
mingsan=rs("lmc3")
%>
<%
rs("o1")=bianma
rs("lmc1")=mingyi
rs("lmc2")=minger
rs("lmc3")=mingsan
rs.Update
rs.Close
response.Redirect("list.asp")
conn.close
set rs=nothing
set conn=nothing
%>
delete.asp
<!--#include file="conn.asp"-->
<%
dim sql
o2=Request.form("o2")
sql="delete * from acc where zth='01' and o1='ztlb'and o2='"&o2&"'"
conn.execute(sql)
conn.close
set conn=nothing
Response.Redirect"list.asp"
%>
无语了,打了很多字,提交时,都给删除了,
做了四个页面,一个显示记录的页面,一个删除,一个添加,一个修改,当然删除和修改时要用到传值的问题,但是现在数据库中没有一个id类似的值用来传值,于是我用了数据库中一个类似的字段,就是代码中的o2,这个字段在数据库中是文本类型的,现在想问,能用这样的字段传值么。如果不能如何改正?
第二个问题,我的删除和修改页面在运行的时候,总是提示SQL语句错误,错在哪里,如何改正?
第三个问题,我那个添加的页面总是不能将数据添加到数据库中,到底是怎么回事,提前声明,我的添加表单没问题,可以将数据提交到添加的页面中,但是无法将数据添加到数据库;
请高手赐教,谢谢啦! 展开
<%
o2=request("o2")
set rs=Server.CreateObject("adodb.recordset")
dim sql
sql="select * from acc where zth='01' and o1='ztlb'"
rs.open sql,conn,1,3
Response.Write("<table><tr><td width=60>编码</td><td width=120>名称(简体)</td><td width=120>名称(繁体)</td><td width=120>名称(英文)</td><td width=150>操作</td></tr>")
rs.movefirst
while not rs.eof
Response.Write("<tr><td > ")
Response.Write(rs("o2"))
Response.Write("</td><td >")
Response.Write(rs("lmc1"))
Response.Write("</td><td>")
Response.Write(rs("lmc2"))
Response.Write("</td><td >")
Response.Write(rs("lmc3"))
Response.Write("</td>")
%><td ><a href="update1.asp?o2=<%=rs("o2")%>">修改</a>
<a href='javascript:if(confirm("您确认要删除该条记录吗?"))location="delete.asp?o2=<%=rs("o2")%>"'>删除</a></td>
<%
rs.movenext
wend
Response.Write("</tr></table>")
rs.close
conn.close
set rs=nothing
set conn=nothing
%>
add1.asp
<%
bianma=Request("bianma" )
mingyi=Request("mingyi" )
minger=Request("minger" )
mingsan=Request("mingsan" )
set rs=Server.CreateObject("adodb.recordset")
dim sql
sql="select * from acc where zth='01' and o1='ztlb'"
rs.open sql,conn,1,3
rs.addnew()
rs("zth")="01"
rs("o1")="ztlb"
rs("o2")=bianma
rs("lmc1")=mingyi
rs("lmc2")=minger
rs("lmc3")=mingsan
rs.update()
response.Redirect("list.asp")
rs.close
conn.close
set rs=nothing
set conn=nothing
%>
update.asp
<%
set rs=Server.CreateObject("adodb.recordset")
dim sql,rs
o2=Trim(Request.QueryString("o2"))
sql="select * from azz where zth='01'and o1 ='ztlb' and o2='"&o2 & "'"
rs.open sql,conn,1,3
bianma=rs("o1")
mingyi=rs("lmc1")
minger=rs("lmc2")
mingsan=rs("lmc3")
%>
<%
rs("o1")=bianma
rs("lmc1")=mingyi
rs("lmc2")=minger
rs("lmc3")=mingsan
rs.Update
rs.Close
response.Redirect("list.asp")
conn.close
set rs=nothing
set conn=nothing
%>
delete.asp
<!--#include file="conn.asp"-->
<%
dim sql
o2=Request.form("o2")
sql="delete * from acc where zth='01' and o1='ztlb'and o2='"&o2&"'"
conn.execute(sql)
conn.close
set conn=nothing
Response.Redirect"list.asp"
%>
无语了,打了很多字,提交时,都给删除了,
做了四个页面,一个显示记录的页面,一个删除,一个添加,一个修改,当然删除和修改时要用到传值的问题,但是现在数据库中没有一个id类似的值用来传值,于是我用了数据库中一个类似的字段,就是代码中的o2,这个字段在数据库中是文本类型的,现在想问,能用这样的字段传值么。如果不能如何改正?
第二个问题,我的删除和修改页面在运行的时候,总是提示SQL语句错误,错在哪里,如何改正?
第三个问题,我那个添加的页面总是不能将数据添加到数据库中,到底是怎么回事,提前声明,我的添加表单没问题,可以将数据提交到添加的页面中,但是无法将数据添加到数据库;
请高手赐教,谢谢啦! 展开
展开全部
1.能用文本类型的传值,但要保证这个字段值的唯一性,不然就跟新到不想更新的记录了。
2.提示的错误信息是什么?如果提示错误,最好在执行语句前也就是
rs.open sql,conn,1,3
conn.execute(sql)
前用Response.Write(sql)在页面显示语句,比较容易的看出错误。正常通过后在把它去掉
看删除中sql="delete * from acc where zth='01' and o1='ztlb'and o2='"&o2&"'"
更新中的sql="select * from azz where zth='01'and o1 ='ztlb' and o2='"&o2 & "'"
都是在and前没加空格。另外显示页面用的是get方式往删除页面传值就是通过url,但是在删除页面用的是o2=Request.form("o2"汪尘)接收值,这是接收困基禅不到通过get方式传过来的值的
3.在你发布的代码中没发现添加的代码无法判断
下面是修改过的语句
list
<%
o2=request("o2")
set rs=Server.CreateObject("adodb.recordset")
dim sql
sql="select * from acc where zth='01' and o1='ztlb'"
rs.open sql,conn,1,3
if not rs.bof and not rs.eof then
Response.Write("<table><tr><td width=60>编码</td><td width=120>名称(简体)</td><td width=120>名称(繁体)</td><td width=120>名称(英文)</td><td width=150>操作</td></tr>")
while not rs.eof
Response.Write("<tr><td > ")
Response.Write(rs("o2"))
Response.Write("</td><td >")
Response.Write(rs("lmc1"))
Response.Write("</td><td>")
Response.Write(rs("lmc2"))
Response.Write("</锋码td><td >")
Response.Write(rs("lmc3"))
Response.Write("</td>")
%>
<td ><a href="update1.asp?o2=<%=rs("o2")%>">修改</a>
<a href='javascript:if(confirm("您确认要删除该条记录吗?"))document.location.href="delete.asp?o2=<%=rs("o2")%>"'>删除</a></td>
<%
rs.movenext
wend
Response.Write("</tr></table>")
else
response.Write("还没有记录!")
end if
rs.close
conn.close
set rs=nothing
set conn=nothing
%>
update
<%
set rs=Server.CreateObject("adodb.recordset")
dim sql,rs
o2=Trim(Request.QueryString("o2"))
sql="select * from azz where zth='01' and o1 ='ztlb' and o2='" & o2 & "'"
rs.open sql,conn,1,3
if not rs.bof and not rs.eof then
bianma=rs("o1")
mingyi=rs("lmc1")
minger=rs("lmc2")
mingsan=rs("lmc3")
rs("o1")=bianma
rs("lmc1")=mingyi
rs("lmc2")=minger
rs("lmc3")=mingsan
rs.Update
end if
rs.Close
conn.close
set rs=nothing
set conn=nothing
response.Redirect("list.asp")
%>
delete
<!--#include file="conn.asp"-->
<%
dim sql
o2=Request.QueryString("o2")
sql="delete * from acc where zth='01' and o1='ztlb' and o2='" & o2 & "'"
conn.execute(sql)
conn.close
set conn=nothing
Response.Redirect"list.asp"
%>
其中update发现是把字段本来的信息更新一遍没什么意义
2.提示的错误信息是什么?如果提示错误,最好在执行语句前也就是
rs.open sql,conn,1,3
conn.execute(sql)
前用Response.Write(sql)在页面显示语句,比较容易的看出错误。正常通过后在把它去掉
看删除中sql="delete * from acc where zth='01' and o1='ztlb'and o2='"&o2&"'"
更新中的sql="select * from azz where zth='01'and o1 ='ztlb' and o2='"&o2 & "'"
都是在and前没加空格。另外显示页面用的是get方式往删除页面传值就是通过url,但是在删除页面用的是o2=Request.form("o2"汪尘)接收值,这是接收困基禅不到通过get方式传过来的值的
3.在你发布的代码中没发现添加的代码无法判断
下面是修改过的语句
list
<%
o2=request("o2")
set rs=Server.CreateObject("adodb.recordset")
dim sql
sql="select * from acc where zth='01' and o1='ztlb'"
rs.open sql,conn,1,3
if not rs.bof and not rs.eof then
Response.Write("<table><tr><td width=60>编码</td><td width=120>名称(简体)</td><td width=120>名称(繁体)</td><td width=120>名称(英文)</td><td width=150>操作</td></tr>")
while not rs.eof
Response.Write("<tr><td > ")
Response.Write(rs("o2"))
Response.Write("</td><td >")
Response.Write(rs("lmc1"))
Response.Write("</td><td>")
Response.Write(rs("lmc2"))
Response.Write("</锋码td><td >")
Response.Write(rs("lmc3"))
Response.Write("</td>")
%>
<td ><a href="update1.asp?o2=<%=rs("o2")%>">修改</a>
<a href='javascript:if(confirm("您确认要删除该条记录吗?"))document.location.href="delete.asp?o2=<%=rs("o2")%>"'>删除</a></td>
<%
rs.movenext
wend
Response.Write("</tr></table>")
else
response.Write("还没有记录!")
end if
rs.close
conn.close
set rs=nothing
set conn=nothing
%>
update
<%
set rs=Server.CreateObject("adodb.recordset")
dim sql,rs
o2=Trim(Request.QueryString("o2"))
sql="select * from azz where zth='01' and o1 ='ztlb' and o2='" & o2 & "'"
rs.open sql,conn,1,3
if not rs.bof and not rs.eof then
bianma=rs("o1")
mingyi=rs("lmc1")
minger=rs("lmc2")
mingsan=rs("lmc3")
rs("o1")=bianma
rs("lmc1")=mingyi
rs("lmc2")=minger
rs("lmc3")=mingsan
rs.Update
end if
rs.Close
conn.close
set rs=nothing
set conn=nothing
response.Redirect("list.asp")
%>
delete
<!--#include file="conn.asp"-->
<%
dim sql
o2=Request.QueryString("o2")
sql="delete * from acc where zth='01' and o1='ztlb' and o2='" & o2 & "'"
conn.execute(sql)
conn.close
set conn=nothing
Response.Redirect"list.asp"
%>
其中update发现是把字段本来的信息更新一遍没什么意义
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询