To read the article online, visit

Creating User Polls, Part 3

  • Read Part 1 of Creating User Polls
  • Read Part 2 of Creating User Polls

    The time has come where we need to update our database. This is done in the file pollResults.asp. You may have noticed that this was the file specified in the FORM's ACTION tag. So, let's ask ourselves, "What does pollResults.asp need to do?" The answer is simple: increment the Votes column for the correct PollOption. We have all the information we need from the previous page, so let's get to it.

    <%@ Language=VBScript %>
    <% Option Explicit %>
    Response.ExpiresAbsolute = Now() - 1

    'All we want to do here is increment the vote count for
    ' the voting option selected...

    Dim objConn
    Set objConn = Server.CreateObject("ADODB.Connection")
    objConn.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & _
         Server.MapPath("Poll.mdb") & ";"

    'Read in our PollOptionID variable
    Dim iPollOptionID
    iPollOptionID = CInt(Request("radPoll"))

    objConn.Execute "UPDATE PollOption SET Votes = Votes + 1 " & _
          "WHERE PollOptionID = " & iPollOptionID

    'Clean Up...
    Set objConn = Nothing
    'We've gotta write a cookie
    Response.Cookies("Voted") = "Yes"
    Response.Cookies("Voted").Expires = DateAdd("d",1,Date)

    'Send the user back to the previous page
    Response.Redirect Request("URLFrom")

    That's all there is to it. Pretty simple, eh? We just update the PollOption table, incrementing the Votes column by one. We then set a cookie to indicate that this user has voted (the cookie is set to expire tomorrow... you can extend this if you like...), and we redirect them back to the page we came from!

    The Dreaded "Operation must use an updateable query" Error
    A number of users have informed me that when trying to run this script they are receiving Operation must use an updateable query error messages. This is usually due to permission settings on the folder the Access database resides in. Check out the Why am I getting "Operation must use an updateable query" errors? FAQ on for more information.

    We've only got one part left to this system, and that is displaying the results! The code that displays the results exists within the same file as the code that shows the voting options. I know it doesn't seem like that, but that's because I wanted to show you just the voting aspect first. For a clearer understanding, you'll want to look through the code, which is available in full at the end of this article...

    So, let's go on to Step 4!

  • Read Part 1 of Creating User Polls
  • Read Part 2 of Creating User Polls
  • Read Part 4 of Creating User Polls

  • Article Information
    Article Title: - Creating User Polls, Part 3
    Article Author: Scott Mitchell
    Published Date: Saturday, July 10, 1999
    Article URL:

    Copyright 2018 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers