Welcome to my ASP Code Website

Sample ASP Poll Code



Trying to take a poll of your users using ASP? Here is some sample ASP poll code that will find out what they think!

First, create a poll table to hold all of the polls and the users' responses. This would have fields for the poll ID, the poll question, each of the four answers the user can choose from, and then an integer for the # of votes for each answer.

Now to show a given poll to your user. Let's say you want to show Poll #1, which asks which season they like best. The four choices are spring, summer, fall, and winter. Put those values into your table along with starting out each # of votes to zero.

Next, you have to show these choices to your user and have them choose an answer. You could name this page poll.asp. For this poll-taking page, your code on your page would look like this:

<%
Set PollStr = Server.CreateObject ("ADODB.Recordset")
SQLText = "SELECT poll_a1, poll_a2, poll_a3, poll_a4, poll_quest from polls where poll_id = 1"
PollStr.Open SQLText, strConnect, adOpenForwardOnly, adLockReadOnly, adCmdText
response.write PollStr("Poll_Quest")
%>
<form action="polls_p.asp" method="post">
<input type="hidden" name="pollid" value="1">
<input type="radio" name="vote" value="1" alt="1"><%=PollStr("Poll_a1")%><BR>
<input type="radio" name="vote" value="2" alt="2"><%=PollStr("Poll_a2")%><BR>
<input type="radio" name="vote" value="3" alt="3"><%=PollStr("Poll_a3")%><BR>
<input type="radio" name="vote" value="4" alt="4"><%=PollStr("Poll_a4")%><BR>
<BR>
<CENTER><input type="submit" name="Vote!" value="Vote!" alt="vote"></CENTER>
</form>
<%
PollStr.close()
set PollStr = Nothing
%>

Step 2 - Code to Process the Poll Vote

ASP Poll / Voting Code

ASPIsFun Poll Area