回 帖 发 新 帖 刷新版面

主题:请各位看看这段代码错在哪里??

向tdxx中的tdlx中添加了值11,12,13,14,15,16,
为什么插入表格中后不管选几,都是显示11呢??



向数据库中添加数据

<%stdlx=request("tdlx")%><select name="tdlx" id="select28">
<option value="">请选择</option>
<option value="11" <%if stdlx="11" then Response.write("selected")%>>出售</option>
<option value="12" <%if stdlx="12" then Response.write("selected")%>>出租</option>
<option value="13" <%if stdlx="13" then Response.write("selected")%>>求购</option>
<option value="14" <%if stdlx="14" then Response.write("selected")%>>求租</option>
<option value="15" <%if stdlx="15" then Response.write("selected")%>>转让</option>
<option value="16" <%if stdlx="16" then Response.write("selected")%>>招商合作</option>
</select>


插入表格的部分:

conn.execute sql
Set Rs=Server.CreateObject("adodb.recordset")
SQL="select * from tdxx where tdlx='11'"
        rs.open sql,conn,1,1
        if not rs.eof then
        tdlx_1=trim(rs("tdlx"))


<%if tdlx_1="11" thenresponse.write "<font color=#CC0000>出售</font>"
elseif tdlx_1="12" thenresponse.write "<font color=#006699>出租</font>"
elseif tdlx_1="13" thenresponse.write "<font color=#333333>转让</font>"
elseif tdlx_1="14" thenresponse.write "<font color=#0000FF>求租</font>"
elseif tdlx_1="15" thenresponse.write "<font color=#FF9900>求购</font>"
elseif tdlx_1="16" thenresponse.write "<font color=#FF9900>招商合作</font>"
end if
%>

回复列表 (共13个回复)

沙发

SQL="select * from tdxx where tdlx='11'"

你这样写可不就是每次都是11吗??应该根据选择的值来组合sql语句。

板凳

谢谢yaozheng,的确是这里的问题,请教应该如何写呢?这对我这个菜鸟来说复杂了点,麻烦帮我指点一下吧!!!

3 楼

没有看明白你说的,你是不是想向表tdxx中的字段tdlx中插入那几个值
conn.execute sql  '这里要这句做什么?因为这前面没有sql语句
Set Rs=Server.CreateObject("adodb.recordset")
SQL="select * from tdxx where tdlx='11'"
        rs.open sql,conn,1,1
        if not rs.eof then
        tdlx_1=trim(rs("tdlx"))

将上面的代码换成
str="11,12,13,14,15,16"
Set Rs=Server.CreateObject("adodb.recordset")
sql="insert into tdxx(tdxx) values('"&str&"')"
conn.execute(sql)

运行后看看表tdxx中有没有新记录

4 楼

不好意思,我可能说的不清楚。

我向数据库中添加已经成功了,在tdxx表中的每条数据,都有个tdlx值,可能是11,或者是12,13,14,15,16,代码如下:

<%stdlx=request("tdlx")%><select name="tdlx" id="select28">
<option value="">请选择</option>
<option value="11" <%if stdlx="11" then Response.write("selected")%>>出售</option>
<option value="12" <%if stdlx="12" then Response.write("selected")%>>出租</option>
<option value="13" <%if stdlx="13" then Response.write("selected")%>>求购</option>
<option value="14" <%if stdlx="14" then Response.write("selected")%>>求租</option>
<option value="15" <%if stdlx="15" then Response.write("selected")%>>转让</option>
<option value="16" <%if stdlx="16" then Response.write("selected")%>>招商合作</option>
</select>


问题是怎样插入网页中呢,比如将tdxx中的一条数据在网页中插入,如果这条数据的tdlx值是11,那么网页中就显示是“出租”;如果另一条数据是12,那么在网页上便显示是“出售”,用下面这段代码实现:

conn.execute sql ------《上面还有语句》
Set Rs=Server.CreateObject("adodb.recordset")
SQL="select * from tdxx where tdlx='11'"---《是不是就是这句有问题呢?》
        rs.open sql,conn,1,1
        if not rs.eof then
        tdlx_1=trim(rs("tdlx"))

这是插入网页中的代码:

<%if tdlx_1="11" thenresponse.write "<font color=#CC0000>出售</font>"
elseif tdlx_1="12" thenresponse.write "<font color=#006699>出租</font>"
elseif tdlx_1="13" thenresponse.write "<font color=#333333>转让</font>"
elseif tdlx_1="14" thenresponse.write "<font color=#0000FF>求租</font>"
elseif tdlx_1="15" thenresponse.write "<font color=#FF9900>求购</font>"
elseif tdlx_1="16" thenresponse.write "<font color=#FF9900>招商合作</font>"
end if
%>

谢谢大哥了!还要再麻烦你呀!!!!

5 楼

SQL="select * from tdxx where tdlx='11'"---《是不是就是这句有问题呢?》
这句得到的结果只能是出售,改成
sql="select *  from tdxx"
还有,你把 thenresponse之间加上一个空格。

6 楼

改了,还是不行啊,还是全部显示11的“出售”啊!

7 楼

我把插入网页的全部代码贴上来,麻烦大哥给看一下,难道是上面的哪句代码影响了那部分代码吗?

<%OpenDataConn
id=RtnReplaceInt(trim(request("id")),0)
action=changechr(trim(request.form("action")))
if action="del" then
if session("del")<>"" then
   if DateDiff("n",session("del"),Now())<5 then
   Response.write("<script>alert(""请隔5分钟再尝试删除!"");location.href=""td_view.asp?id="&id&""";</script>")
Response.end
end if
end if
sqlDel="select * From tdxx Where delpass='"&changechr(trim(request.form("scmm")))&"' and id= "&id
Set rsDel= Server.CreateObject("ADODB.Recordset")
rsDel.open sqlDel,conn,1,3
If not (rsDel.EOF and rsDel.BOF) then
rsDel.delete
rsDel.update
else
session("del")=now()
Response.write("<script>alert(""密码不正确,您的IP已被记录,请不要非法删除数据!"");location.href=""td_view.asp?id="&id&""";</script>")
Response.end
end if
rsDel.close
set rsDel=nothing
Response.Redirect "../"
end if
sql="update tdxx set hits=hits+1 where id="&id

conn.execute sql
set rsv=server.createobject("adodb.recordset")
If session("manager")<>"" Then
sqlv="select * from tdxx where id="&id
else
sqlv="select * from tdxx where sh='1' and id="&id 
end if
rsv.open sqlv,conn,1,1
if not rsv.eof then
lxr=rsv("lxr")
fangwei=rsv("fangwei")
tdlx=rsv("tdlx")

---------------------------------------下面是出错的部分-----
conn.execute sql
str="11,12,13,14,15,16"
Set Rs=Server.CreateObject("adodb.recordset")
sql="select *  from tdxx"
        rs.open sql,conn,1,1
        if not rs.eof then
        tdlx_1=trim(rs("tdlx"))

end if

8 楼

顶一下,请各位帮忙看一看呀!!我真是被难住了

9 楼

---------------------------------------下面是出错的部分-----
conn.execute sql
str="11,12,13,14,15,16" '这里的str起什么作用?下面没有用到
Set Rs=Server.CreateObject("adodb.recordset")
sql="select *  from tdxx"
rs.open sql,conn,1,1 '这里查询到的是一批记录,而不是一条记录
if not rs.eof then
tdlx_1=trim(rs("tdlx")) '所以这里这句就有问题了
end if


10 楼

不好意思,麻烦您帮我再指导一下吧??谢谢了!

conn.execute sql
str="11,12,13,14,15,16"----------《这一句去掉吗?》
Set Rs=Server.CreateObject("adodb.recordset")
sql="select *  from tdxx(tdlx)  values('"&str&"')"---《这里应该怎么写呢?》
        rs.open sql,conn,1,1
        if not rs.eof then
        tdlx_1=trim(rs("tdlx"))

我来回复

您尚未登录,请登录后再回复。点此登录或注册