主题:  投票的结果无法更新?

yiliaocheng

职务:普通成员
等级:2
金币:2.0
发贴:631
#12006/4/10 19:42:21
我做投票的时候,显示投票没问题,投票也没问题,可是结果没办法传到数据库更新啊!下面是显示投票的页面代码:
<%sql="select top 1 * from vote where check=1 "
rsleft.Open sql,conn,1,1
if rsleft.bof and rsleft.eof then
response.Write "<p align=center>暂时没有投票</p>"
else
response.write "<form name='VoteForm' method='post' action='vote.asp' target='_blank'>"
response.write "<b>"&rsleft("title") & "</b>"
if rsleft("type")="0" then
for i=1 to 10
if trim(rsleft("select" & i) & "")="" then exit for
response.write"<br>"
response.Write"<input type='radio' name='VoteOption' value='" & i & "'>" & rsleft("select" & i)
next
else
for i=1 to 10
if trim(rsleft("select" & i) & "")="" then exit for
response.write"<br>"
response.Write"<input type='checkbox' name='VoteOption' value='" & i & "'>" & rsleft("select" & i)
next
end if%><br>
<input name='VoteType' type='hidden' value='<%=rsleft("type")%>'>
<input name='Action' type='hidden' value='vote'>
<input name="id" type="hidden" value="<%=rsleft("id")%>"/>
<input type="image" src="images/votesubmit.gif" alt="我要投票">
<a href='Vote.asp?Action=Show' target='_blank'><img src='images/voteview.gif' border='0' alt='结果'></a></form>
<%end if
rsleft.close
%>
以下是投票检查更新及显示结果页:
<!--#include file="conn.asp"-->
<html><head><link rel="stylesheet" href="css.css" type="text/css">
<title>马列协会</title>
<style type="text/css">
<!--
body {
    background-image: url();
}
-->
</style>
</head>
<body text="#000000" leftmargin="0" topmargin="20" marginwidth="0" marginheight="0">
<%
Action=Request("Action")
VoteType=request("VoteType")
VoteOption=replace(request("VoteOption")," ","")
id=request("id")

if action="vote" and VoteOption="" then
    response.write "<script language='javascript'>"
    response.write "alert('您什么也没有选择!');"
    response.write "location.href='vote.asp?action=view';"
    response.write "</script>"
    response.end
end if

if action="vote" and request.cookies("buyok_Voted")=request.ServerVariables("remote_address") then
    response.write "<script language='javascript'>"
    response.write "alert('您已经投票了,不能重复投票!');"
    response.write "location.href='vote.asp?action=view';"
    response.write "</script>"
    response.end
end if

'投票
If Action = "vote" And VoteOption<>"" Then
arrOptions=split(VoteOption,",")
for i=0 to ubound(arrOptions)
    answer=cstr("answer"&arrOptions(i))
    conn.execute "Update Vote set "&answer&"="&answer&"+1 where id="&id
next
    '将用户IP写入COOKIES防止重复投票
response.cookies("buyok_Voted") = request.ServerVariables("remote_address")
' response.cookies("buyok_Voted").expires=now+1

    response.write "<script language='javascript'>"
    response.write "alert('投票已提交,感谢您的参与!');"
    response.write "location.href='vote.asp?action=view';"
    response.write "</script>"
    response.end
End If

'显示投票结果
rsVote = conn.execute("Select * from Vote where id="&id)
    totalVote=0
    for i=1 to 10
    if rsVote("select" & i)="" then exit for
    totalVote=totalVote+rsVote("answer"& i)
    next
    if totalVote=0 then totalVote=1

%>

<table cellSpacing="0" cellPadding="1" width="500" align="center" bgColor="#f4f4f4" border="0">
<tbody>
<tr>
<td>
<table cellSpacing="0" cellPadding="10" width="496" border="0">
<tbody>
<tr>
<td bgColor="#f4f4f4">
<table cellSpacing="10" cellPadding="0" width="460" align="center" border="0">
<tbody>
<tr>
<td><b><%=rsVote("title")%></b></td>
</tr>
<tr>
<td>共有 <font color=red><%=totalVote%></font> 人参与投票</td>
</tr>
<tr>
<td bgColor="#007ecc">
<table cellSpacing="1" cellPadding="2" width="460" border="0">
<tbody>
        <%
            for i=1 to 10
            if trim(rsVote("select" & i) & "")="" then exit for
        %>
            <tr>
<td bgColor="#ffffff"><%=rsVote("select"& i)%></td>
<td bgColor="#ffffff">
        <%
        perVote=round(rsVote("answer"& i)/totalVote,2)
        response.write "<img src='images/small/vote.gif' width='" & round(200*perVote) & "' height=10>"
        perVote=perVote*100
        if perVote<1 and perVote<>0 then
            response.write "&nbsp;0" & perVote & "%"
        else
            response.write "&nbsp;" & perVote & "%"
        end if
        %>
            </td>
<td align="center" bgColor="#ffffff"><%=rsVote("answer"&i)%></td>
</tr>
        <%
        next
        rsVote.Close
        Set rsVote = Nothing
        %>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tbody>
<tr>
<td align="middle">感谢您的参与!</td>
</tr>
<tr>
<td align="right">【<a href="javascript:window.close()">关闭窗口</a>】</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
希望各位指正是什么回事

编辑历史:[此帖最近一次被 蓝鲸 编辑过(编辑时间:2006-04-10 21:10:30)]


yiliaocheng

职务:普通成员
等级:2
金币:2.0
发贴:631
#22006/4/11 19:17:39
怎么没人回答,都不知道么?



蓝鲸

职务:版主
等级:5
金币:42.1
发贴:2614
#32006/4/12 1:39:53
看了一回,没看出那一段时更新数据库语句
太长了

如果你觉太繁了,教你个方法,就是把不太可能出错的代码暂时注释掉,集中处理一段代码。如果还不行,再注释一些,从外向内包围。


非常大鱼