- ASP - Database Table Display
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·What's New?
Mail List


Vote/User Poll (Hyperlink Input, DB and Cookie)
"Ballot Stuffing" in any Vote/User Poll can be thwarted in many number of ways.  One of the most popular methods is by writing a cookie (a small text file) to the users computer.  Users can prevent this, but most browser come set up to be pretty tolerant of cookies. Also, users can delete cookies and resubmit a vote from a new browser session, but most users can't be bothered to remove files to spoil survey results (unless their really persistent).  The following example will display four hyperlinked choices to a question on the users first visit (and any subsequent visit until they vote).  Once the user votes a cookie is written to the users PC with the name of the poll, their vote and and expiration date of seven days and an Access db tracks the input and tracks the results.
View the Output
Text View
Print View
Mail this Link
Download the Code
View the Data

'Defines the name of the poll being taken
'Assigns the varible accessdb to the name of the access the conatins the poll results
cn="driver={Microsoft Access Driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath(accessdb)
set rs = server.createobject("ADODB.Recordset")
taken= (request.cookies (poll_name)("u_choice"))
'Assigns a variable to see if the user has entered this poll previously
select case u_choice
'Check to see in the user entered a valid choice
case "1","2","3","4" 
if taken = "" then
'Write the name of the poll and the latest choice to the cookie
response.cookies (poll_name)("u_choice") = u_choice
'Make the cookie expire in seven days
response.cookies (poll_name).expires = DATE + 7
'Add one to the count of the users choice
sql = "insert into poll (choice" & u_choice &") "
sql = sql & "values ("& 1 &")"
rs.Open sql, cn
'Flag to indicate that a vote was entered 
end if

<% case else
'Ignore bad request from user input in the address bar
end select

<title> Poll)</title>
<body bgcolor="#FFFFFF">
A Question with four possible choices...<br>
'Check to see if the user voeted previously or on the current iteration
if (taken <> "") or (just_voted= "Yes") then
'Grab all of the poll results from the db
sql= "select distinctrow sum(choice1) as sum_choice1, " 
sql= sql & "sum(choice2) AS sum_choice2, sum(choice3) AS sum_choice3, "
sql= sql & "sum(choice4) AS sum_choice4, count(*) AS total_votes "
sql= sql & "from poll;"
rs.Open sql, cn
total1=rs ("sum_choice1")
total2=rs ("sum_choice2")
total3=rs ("sum_choice3")
total4=rs ("sum_choice4")
count=rs ("total_votes")

Choice 1: <%= formatnumber((total1/count)*100,1) %>% &nbsp;
Choice 2: <%= formatnumber((total2/count)*100,1) %>% &nbsp;
Choice 3: <%= formatnumber((total3/count)*100,1) %>% &nbsp;
Choice 4: <%= formatnumber((total4/count)*100,1) %>% &nbsp;
Total Votes: <%= formatnumber(count,0,0) %><br>
'If this is the users first time here or if they have not
'voted on a previous visit display the question and hyperlinked choices

<a href="<% request.servervariables("script_name") %>?u_choice=1">Choice 1</a>
<a href="<% request.servervariables("script_name") %>?u_choice=2">Choice 2</a>
<a href="<% request.servervariables("script_name") %>?u_choice=3">Choice 3</a>
<a href="<% request.servervariables("script_name") %>?u_choice=4">Choice 4</a>
<% end if %>




ASP: What's New? | Articles | Script Writers | Database Display | Read/Write
Server Variables | Response Objects | Random Events | Miscellaneous
HTML: Forms | Hyperlinks | Headers | Tables | Hyperlinks | Headers | Text Display
JavaScript: Document Info | Forms | Images | Navigation | Script Writers
CSS: Basics | Page Display | Text Display | Script Writers | Miscellaneous
  • 2014 michael kors
  • air max women 2013
  • 2014 michael kors
  • air max 2014
  • oakley glasses
  • oakley glasses

  • Maps: Map Script Writers | Bing Maps | Google Maps
  • bottes fr
  • ugg boot
  • Privacy Statement is hosted by
    Donate Food Online with a Mouse Click at
    Donate Land Online with a Mouse Click at
    © 1999 - 2018
    All Rights Reserved

  • Kids jordan 6 rings
  • Jordan retro 10
  • Jordan retro 3