Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Preventing multiple votes in Poll

Posted on 2004-08-04
16
Medium Priority
?
581 Views
Last Modified: 2008-03-10
Hello all!  I have a quick and easy poll setup in ASP.  It works like a charm, but I would like to be able to block a user from voting more than once.  How would I modify my code to do so?

<body>
<form method="post" action="poll.asp">
What is the best web development resource?
<table summary="" class="poll">
      <tr>
            <td><input type="radio" name="poll" value="Spoono"></td>
            <td>Spoono</td>
      </tr>
      <tr>
            <td><input type="radio" name="poll" value="EE"></td>
            <td>Experts Exchange</td>
      </tr>
      <tr>
            <td><input type="radio" name="poll" value="Google"></td>
            <td>Google</td>
      </tr>
      <tr>
            <td></td>
            <td><input type="submit" value="Submit" class="submit"></td>
      </tr>
</table>
</form>
<table style="width: 250px;">
<tr>
<td>
Results:
<%
Dim oConnA
Dim DRIVER
Dim SQLA
Dim poll
Set oConnA=Server.CreateObject("ADODB.Connection")
oConnA.Open "DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=c:\Inetpub\wwwroot\db1.mdb;"
poll = Request.Form("poll")
if poll = "" or IsNull(poll) then
else
SQLA="insert into Poll(results, count) Values ('" & poll & "', 1)"
oConnA.execute(SQLA)
end if
%>
<%
Dim MXID
Dim MXIDER
SQLE="select Max([Ref ID]) AS MXID from Poll"
set inTableC = oConnA.execute(SQLE)
MXIDER = inTableC("MXID")
%>
<br><br>
<%
Dim inTableB
Dim responseone
responseone = "Spoono"
SQLB="select Sum(count) from Poll WHERE results = '"&responseone&"' "
inTableB = oConnA.execute(SQLB)

for each xfield in inTableB
percentage1 =  (xfield.value / MXIDER) * 100
percentage1a = left(percentage1, 2)
      response.write "<table><tr><td class=""left"">" & xfield.value & " ("& percentage1a &"%)</td><td width="& percentage1 * 2 & " class=""graph""></td></tr></table>"
next
%>
<%
Dim inTableC
Dim yfield
Dim responsetwo
responsetwo = "EE"
SQLC="select Sum(count) from Poll WHERE results = '"&responsetwo&"' "
inTableC = oConnA.execute(SQLC)
for each yfield in inTableC
percentage2 = (yfield.value / MXIDER) * 100
percentage2a = left(percentage2, 2)
      response.write "<table><tr><td class=""left"">" & yfield.value & " (" & percentage2a & "%)</td><td width=" & percentage2 * 2 & " class=""graph""></td></tr></table>"
next
%>
<%
Dim inTableD
Dim zfield
Dim responsethree
responsethree = "Google"
SQLD="select Sum(count) from Poll WHERE results = '"&responsethree&"' "
inTableD = oConnA.execute(SQLD)
for each zfield in inTableD
percentage3 = (zfield.value / MXIDER) * 100
percentage3a = left(percentage3, 2)
      response.write "<table><tr><td class=""left"">" & zfield.value & " (" & percentage3a & "%)</td>"
      response.write "<td width=" & percentage3 * 2 &  " class=""graph""></td></tr></table>"
next
%>
<%
response.write "<b>Total Votes:</b> " & MXIDER & ""
%><br><br>
<div style="font-size: 7pt; text-align: center;">This poll is not scientific - multiple votes are allowed per person</div>
</td>
</tr>
</table>
</body>
0
Comment
Question by:flow79
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
  • +2
16 Comments
 
LVL 5

Expert Comment

by:millsoft
ID: 11716663
1. Add IP address to your POLL table, & insert that value into the POLL table also (IP can be found in the request object I believe).
2. Create a unique index on the IP address field.
3. Catch resulting insert errors from duplicates.

Quick and dirty, but it will prevent multiple people at the same IP address from participating.  Note however, that may not be what you want.  Different users in the same company often have the same IP address when appearing at an external website (due to Network Address Translation at their firewall).  

But, if it suits your purpose it's very easy to implement.

Brad
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11716669
There is no real way to stop that. You could try placing a cookie when the user votes and then not allow duplicates, but saavy users can get around that and some users don't allow cookies at all.

FtB
0
 
LVL 5

Expert Comment

by:millsoft
ID: 11716671
As an alternative to 1 per IP, you could also insert a combination of IP address & time stamp (say minute or hour), so that the same IP address could be used but only once per hour or minute.  
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:golfDoctor
ID: 11716684
Kinda difficult to be full proof.  You would need to store the IP Address (HTTP_REFERER) in the poll table with the vote.  Then compare the IP Address in table to new vote IP Address, and if in the table, disallow vote.

But, this would prevent voting from within the same businesses.  Many businesses have multiple users in a domain, but on one external IP address.
0
 
LVL 13

Author Comment

by:flow79
ID: 11716686
can you show me how to actually implement it in the code?

I dont really mind about the multiple users at the same company (its not internal) - just a nice bonus feature a user can set up on a blog site.
0
 
LVL 13

Author Comment

by:flow79
ID: 11716694
or fritz - how do i set up the cookie?  any help using the code i already have would be great!
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 2000 total points
ID: 11716906
<%
%>


Results:
<%
Dim oConnA
Dim DRIVER
Dim SQLA
Dim poll
if request.cookies("bolCastVote") = "" then
  Response.Cookies("bolCastVote")="True"
  Response.Cookies("firstname").Expires=#May 10,2020#
  Set oConnA=Server.CreateObject("ADODB.Connection")
  oConnA.Open "DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=c:\Inetpub\wwwroot\db1.mdb;"
  poll = Request.Form("poll")
  if poll = "" or IsNull(poll) then
  else
   SQLA="insert into Poll(results, count) Values ('" & poll & "', 1)"
   oConnA.execute(SQLA)
else
response.write("You have already voted!")
end if
%>
0
 
LVL 16

Expert Comment

by:golfDoctor
ID: 11716959
My posts was only 2 minutes later, and it took a while to type.  I am aware of the policies, thanks.
0
 
LVL 13

Author Comment

by:flow79
ID: 11716971
thats seems to produce errors:

it opened fine the first time - but when i tested it (selected an option and submitted), it shot back with the error:

Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: ''
/test/poll.asp, line 73

line 73 is: set inTableC = oConnA.execute(SQLE)
0
 
LVL 13

Author Comment

by:flow79
ID: 11716987
actually, i think i got it - i had to remove the connection string from within the if-then - but it still does stop the voting.    Thanks Fritz!
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11716995
Glad to have helped,

FtB
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11717027
I recommend millsofts answer.  When using cookies, the user controls cookies and all they have to do is erase the cookies.  If you store IP, then it's under your control.  If the person really wants to vote again, then cookies will not stop them.

Just a thought...
0
 
LVL 13

Author Comment

by:flow79
ID: 11717062
alorentz - i understand that issue - but this poll is just an added feature users can add to their blogging pages.  It does not need to be scientific (it is not so important that if someone turned off cookies, it would be a big deal).  But if I ever do need to make a poll completely scientific (by truly only allowing 1 vote per IP), i will use that method.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11717406
@alorentz--

I already mentioned that above:

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21082091.html#11716669. The problem, as others have already pointed out, that many users may share the same IP if they work for the same company, have the same ISP and etc.

Fritz the Blank
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11718985
@golfDoctor--

Fair enough. If you like, I am happy to delete the comment.

Fritz the Blank
Page Editor
ASP Topic Area
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question