How to use ASP to establish a voting mechanism on your own website (i)

Source: Internet
Author: User
Batman Translation Finishing

A very good ASP program to build your own voting system. Read it carefully, and as long as you can understand the key technologies in the middle, you can build your own polling station on your website. The papers were hastily sorted out and I hope you will understand.
All rights reserved:
ASP Polls
Version 1.0
Tipped Cow Development and adrenalin Labs
Structure Simple Introduction:
Access database design structure:
Poll table primary field name: Pollname,pollcreator,pollquestion,password,choice1,choice2
Choice3,choice4,choice5,id (AutoNumber), GetName
Pollresults table fields: Pollid,pollanswer,name
1. Document Db.inc
<%
Application ("asp_poll") = "Asp_poll"
cnstring = "Driver={microsoft Access DRIVER (*.mdb)};"
cnstring = cnstring & "dbq=" & Server.MapPath ("Events.mdb")
Application ("asppolldsn") = cnstring
%>
1. Document Creat_poll1.asp
<% title= "Poll Generator"%>
<title><%=Title%></title>
<body>
<div align= "left" ><br" >another Joint product from <a href= "Http://www.ncws.com/tippycow" >tipped Cow development</a> and <a href= "http://dstoflet.calweb.com" >adrenalin labs</a>
<br><br>
</div>
<center>

<%
Response.Write "<font face= ' Arial ' >"
If Request ("errormessage") <> "Then
Response.Write "<b>error! </b> "& Request (" ErrorMessage ")
Else
Response.Write "Please complete the form below to begin creating your own."
End If
%>

<br><br>
<table border=2 cellspacing=0 cellpadding=0><tr><td>
<form method= "POST" action= "create_poll2.asp" >


<table border=0 cellspacing=0 cellpadding=10 width=500><tr>
&LT;TD colspan=2 bgcolor= #000000 align=center class= "Bold2" >
Enter Your Name as the Poll Creator
</td>
</tr><tr>
&LT;TD bgcolor= #ffffff width=25% class= "bold" >poll creator:</td>
&LT;TD bgcolor= #ffffff >
<input type= "text" Name= "creator" value= "<%=request (" creator ")%>" size=20 class= "Input" >
</td>
</tr>
</table>

</td></tr>
<tr><td>

<table border=0 cellspacing=0 cellpadding=10 width=500><tr>
&LT;TD colspan=2 bgcolor= #000000 align=center class= "Bold2" >
Create a Password for Your Poll and Can Modify It at a
Later time
</td>
</tr><tr>
&LT;TD bgcolor= #ffffff width=25% class= "bold" >poll Admin password:</td>
&LT;TD bgcolor= #ffffff >
<input type= "password" name= "password" value= <%=request ("password")%> "size=10 maxlength=10 Class=input>
</td>
</tr>
</table>

</td></tr>
<tr><td>

<table border=0 cellspacing=0 cellpadding=10 width=500><tr>
&LT;TD colspan=2 bgcolor= #000000 align=center class= "Bold2" >
Give Your Poll a Unique Name
</td>
</tr><tr>
&LT;TD bgcolor= #ffffff width=25% class= "bold" >poll name:</td>
&LT;TD bgcolor= #ffffff >
<input type= "text" name= "name" value= "<%=request (" name ")%>" Size=20 class=input>
</td>
</tr>
</table>

<table border=0 cellspacing=0 cellpadding=10 width=500><tr>
&LT;TD colspan=2 bgcolor= #000000 align=center class= "Bold2" >
Do your want to have the user enter their name?
</td>
</tr><tr>
&LT;TD bgcolor= #ffffff width=25% class= "bold" >require user to enter their name:</td>
&LT;TD bgcolor= #ffffff class= "Bold" >
Yes<input type= "Radio" name= "GetName" value= "1" ><br>
No <input type= "Radio" name= "GetName" value= "0" checked>
</td>
</tr>
</table>

</td></tr>
<tr><td>

<table border=0 cellspacing=0 cellpadding=10 width=500><tr>
&LT;TD colspan=3 bgcolor= #000000 align=center class= "Bold2" >
Select Poll Type
</td>
</tr><tr>


&LT;TD colspan=2 bgcolor= #ffffff class= "bold" >what type of poll question
Do your wish to create?</td>
&LT;TD bgcolor= #ffffff class= "Bold" >
<input type= "Radio" name= "Polltype" value= "Yes_no" >Yes/No<br>
<input type= "Radio" name= "Polltype" value= "Multiple_choice" >multiple choice<br>
</td>
</tr>
</table>
</td></tr></table>
<table width=500><tr>
&LT;TD colspan=3 align=right>
<input type= "Submit" value= "Next" class= "inline" >
</td></tr>
</table>

</center>
</body>
3. Document Connect.asp
<%
id = Request ("id")
If id = "" Then
ID = 0
End If
num = Request ("Choice")

If num <> "" Then

Set conn = Server.CreateObject ("ADODB. Connection ")
Dsnpath = "Driver={microsoft ACCESS DRIVER (*.mdb)};"
Dsnpath = Dsnpath & "dbq=" & Server.MapPath ("Events.mdb")
Conn.Open Dsnpath
Set rs = Server.CreateObject ("ADODB.") RecordSet ")
Rs. Open "Pollresults", Conn, 3, 3
Rs. AddNew
RS ("pollid") = Cint (ID)
RS ("name") = Request ("name")
RS ("pollanswer") = Cint (num)
Rs. Update
Rs. Close
Set rs = Nothing
Conn. Close
Set conn = Nothing
End If

If Request ("Return_page") <> Empty Then
Response.Cookies ("pollid") = ID
Response.Redirect Request ("Return_page")
End If
%>

<body bgcolor= "#4f4f4f" text= "#c0c0c0" link= #f5fcdc vlink= #f5fcdc >
<center>

<% If num <> "" Then%>
<br><br>
<table border=0 cellspacing=0 cellpadding=0><tr>

&LT;TD colspan=3 align=center><font face= "Verdana" >
Your selection has been recorded.
</td></tr>
</table>

<% End If%>
<br><br>
<%

Set conn = Server.CreateObject ("ADODB. Connection ")
sql = "SELECT * from Poll where id =" & Cint (ID)
Dsnpath = "Driver={microsoft ACCESS DRIVER (*.mdb)};"
Dsnpath = Dsnpath & "dbq=" & Server.MapPath ("Events.mdb")
Conn.Open Dsnpath
Set rs = conn.execute (SQL)
If Rs. EOF = False Then
%>
<table border=1 cellspacing=0 cellpadding=5 width=500 bordercolor= #2f2f4f ><tr>
&LT;TD colspan=3 bgcolor= #2f2f4f align=center><font face= "Verdana" color= #f5fcdc >
<%=rs ("Pollquestion")%>
</td></tr>
<%
Dim Choices (6)
Dim Responses (6)
For I=1 to 5
Choice = rs ("Choice" & I)
Choices (I) = Choice
If choice <> "" Then
Set conn2 = Server.CreateObject ("ADODB. Connection ")
sql = "Select COUNT (pollanswer) from pollresults where Pollid =" & Cint (ID) & "and pollanswer=" & I
Dsnpath = "Driver={microsoft ACCESS DRIVER (*.mdb)};"
Dsnpath = Dsnpath & "dbq=" & Server.MapPath ("Events.mdb")
Conn2.open Dsnpath
Set rs2 = conn.execute (SQL)
If rs2. EOF = False Then
Response.Write "<tr><td colspan=2 bgcolor= #4f4f4f align=center width=400><font face= ' Verdana ' color=# F5fcdc> "
Response.Write Choice
Response.Write "</td>"
Responses (I) = rs2 (0)
Response.Write "<td colspan=1 bgcolor= #4f4f4f align=right><font face= ' Verdana ' color= #f5fcdc ><b>" & Rs2 (0) & "</b></td>"
Response.Write "</tr>"
End If
Rs2. Close
Conn2. Close
End If
Next
End If
%>

</table>

<br><br>

<table >
&LT;TD colspan=3 align=center><font face= "Arial" >
<font face= "Ms Sans Serif" ><b> polls results</b></font>
</td></tr>

<%
Total = 0
For I=1 to 5
Responsecount = Responses (I)
If responsecount <> "" Then
Total = Total + Cint (responsecount)
End If
Next
For I=1 to 5
Choice = Choices (I)
Responsecount = Responses (I)
If choice <> "" Then
Response.Write "<tr><td colspan=1 align=left><font face= ' Arial ' >"
Response.Write Choice
Response.Write "</td>"
Response.Write "<td colspan=2 width=400><table border=1 cellspacing=0><tr><td bgcolor=blue Align =center width= "& Converttopix (Responsecount) &" ><font face= ' ms Sans Serif ' color=white><b> ' & Amp Converttopercent (Responsecount) & "</td></tr></table></td>"
Response.Write "</tr>"
End If
Next

Function Converttopix (SZ)
If Sz = 0 Then
Converttopix = 0
Else
Converttopix = Cint (400/total * sz)
End If
End Function

Function converttopercent (SZ)
If Sz = 0 Then
Converttopercent = "0%"
Else
Converttopercent = FormatPercent (sz/total, 2)
End If
End Function

%>

</table>


<% If num = "" Then%>
<br><br>
<table border=0 cellspacing=0 cellpadding=0><tr>

&LT;TD colspan=3 align=center><font face= "Verdana" >
<a href= "default.asp?id=<%=id%>" >add Your vote</a>
</td></tr>
</table>

<% End If%>

<br><br>
<table WIDTH=100%&GT;&LT;TR&GT;&LT;TD align=right>
<table border=1 cellpadding=5 cellspacing=0 bordercolor= #f5fcdc ><tr><td bgcolor= #2f2f4f >
<font face= ' Verdana ' size=+1><a href= ' javascript:history.back () ' >Back</a>
</td></tr></table>
</td></tr></table>

</center>
</body>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.