votedo.asp
来自「ASP入门与提高实用教程 源文件(上传网站)」· ASP 代码 · 共 223 行
ASP
223 行
<!--#include file="conn.asp"--><%
dim multi,id
dim svote,mvote
dim foundErr
dim rs,exec1,sql
dim i,k
dim alvote,total
dim malvote()
foundErr=false
svote=encodestr(Request.form("svote"))
mvote=encodestr(Request.form("mvote"))
ID=encodestr(Request.form("ID"))
multi=encodestr(Request.form("multi"))
set rs=server.createobject("adodb.recordset")
'************************
'开始检查非法操作或错误
'************************
exec1="select * from vote where id="&cint(id)
rs.open exec1,conn,1,1
if rs.eof then
rs.close
set rs=nothing
conn.close
set conn=nothing
response.write "不存在这个投票!!<br>"
response.end
end if
if cint(multi)<>rs("multi") then
rs.close
set rs=nothing
conn.close
set conn=nothing
response.write "投票类别错误!!<br>"
response.end
end if
rs.close
'************************
'每IP每小时只能投一次票
'************************
sql="select * from [votelog] where voteID="&ID&" and voteIP='"&request.servervariables("remote_addr")&"' and voteTime between #"&dateadd("h",-1,now())&"# and #"&now()&"#"
rs.open sql,conn,1,1
if not rs.eof then
rs.close
set rs=nothing
conn.close
set conn=nothing
response.write "您已经投过票了!!<br>"
response.end
end if
rs.close
if multi=1 then
if mvote="" then
session("error")="至少选择一个选项!!<br>"
foundErr=true
end if
else
if svote="" then
session("error")="请选择一个选项!!<br>"
foundErr=true
end if
end if
if foundErr then
connclose()
response.redirect("error.asp")
end if
'************************
'没有错误,开始操作
'************************
if multi=1 then
mvote=split(mvote,",")
k=ubound(mvote)
redim malvote(k)
for i=0 to k
if mvote(i)<>"" then
exec1="select * from vote where id="&cint(id)&" and options="&cint(mvote(i))
rs.open exec1,conn,1,3
malvote(i)=rs("votes")
rs("votes")=rs("votes")+1
rs.update
rs.close
end if
next
else
exec1="select * from vote where id="&cint(id)&" and options="&cint(svote)
rs.open exec1,conn,1,3
alvote=rs("votes")
rs("votes")=rs("votes")+1
rs.update
rs.close
end if
exec1="select top 1 * from votelog"
rs.open exec1,conn,2,3
rs.addnew
rs("voteIP")=request.servervariables("remote_addr")
rs("voteID")=ID
rs.update
rs.close
sql="select sum(votes) from vote where id="&cint(id)
rs.open sql,conn,1,1
total=rs(0)
rs.close
set rs=nothing
connclose()
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.style4 {
color: #3366FF;
font-style: italic;
}
.ttr {
color: #3366FF;
margin: 0px;
padding: 0px;
border-top: thin none;
border-right: medium none;
border-bottom: 1px dotted #A4D1FF;
border-left: thin none;
text-indent: 10pt;
}
.style7 {
color: #3300CC;
font-style: italic;
}
-->
</style>
</head>
<body>
<table width="300" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#9B9BFF">
<tr>
<td width="21%" height="35" align="center" bgcolor="#BBD3F4" class="style4">投票已经成功完成!!</td>
</tr>
<tr>
<td height="168" bordercolor="#333333" bgcolor="#D7E8FB"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="ttr">你的投票是:
<%
if multi=0 then
response.write Chr(64+cint(svote))
else
for i=0 to k
response.write Chr(64+cint(mvote(i)))&","
next
end if
%>
</td>
</tr>
<tr>
<td class="ttr">
<% if multi=1 then response.write "分别"%>
有
<%
if multi=0 then
response.write alvote
else
for i=0 to k
response.write malvote(i)&","
next
end if
%>
人与你有同样的观点.</td>
</tr>
<tr>
<td class="ttr">总的投票数是:<%=total%></td>
</tr>
<tr>
<td class="ttr">点击<a href="stat.asp?id=<%=id%>" class="style7">这里</a>查看详细信息.</td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" height="28" border="0" cellpadding="0" cellspacing="0" bgcolor="#B3B8D9">
<tr>
<td align="center"><input type="submit" name="Submit" value="返回" onClick="javascript:history.go(-1)">
</td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?