Ir para conteúdo
Fórum Script Brasil
  • 0

Votar Várias Vezes Numa Enquete


marcos_804

Pergunta

GALERA, DIGO DESDE JÁ, ESTE CÓDIGO NÃO FOI FEITO POR MIM, POR ISSO A MALDITA DÚVIDA. COMO POSSO FAZER PARA NÃO ENVIAR COOKIES AO CLIENTE E COM ISSO PERMITI-LO VOTAR MUITAS VEZES?

<%

'Dimension variables

Dim adoCon    'Database Connection Variable

Dim rsWeeklyPoll  'Database Recordset Variable to hold the eweekly poll recordset

Dim strAccessDB  'Holds the Access Database Name

Dim strSQL    'Database query sring

Dim strPollQuestion  'Holds the poll question

Dim intPollIDNum  'Holds the Poll ID Num

Dim intSelectionLoopCounter 'Loop counter to display the poll selections

Dim intVotedIDNo  'Holds the ID Number the last vote the user voted in if there is one

Dim blnCheckForPoll  'Set to false if there are no weekly polls in the database

Dim blnAlreadyVoted 'Set to true if the user has voted in this weeks poll

'Error Trapping

On Error Resume Next

'Intilaise variables

blnCheckForPoll = True

blnAlreadyVoted = Flase

intPollIDNum = 1

'Initialise the strAccessDB variable with the name of the Access Database

strAccessDB = "weekly_poll"

'Create a connection odject to the database

Set adoCon = Server.CreateObject("ADODB.Connection")

Set rsWeeklyPoll = Server.CreateObject("ADODB.Recordset")

'Open connection to the database driver

adoCon="DRIVER={Microsoft Access Driver (*.mdb)};"

'Open Connection to database

adoCon = adoCon & "DBQ=" & server.mappath(strAccessDB)

'Initalise the strSQL variable with an SQL statement to query the database

strSQL = "SELECT * FROM tblPolls ORDER By id_no DESC;"

'Query the database

rsWeeklyPoll.Open strSQL, adoCon, 3

'Check there is a weekly poll to display

If rsWeeklyPoll.EOF Then

'If there is no weekly poll in the database chenge the blnCheckForPoll variable to false

blnCheckForPoll = False

Else

'Read in the polling question from the database

strPollQuestion = rsWeeklyPoll("Question")

'Read in the Weekly Poll ID number

intPollIDNum = CInt(rsWeeklyPoll("id_no"))

'Loop round to read in the number of votes cast

For intReadInVotesLoopCounter = 1 To 7

 

  'Read in the total number of votes cast

  intToatalPollVotes = intToatalPollVotes + CInt(rsWeeklyPoll("Votes_" & intReadInVotesLoopCounter & ""))

Next

'Check the user has not already voted by reading in a cookie from there system

'Read in the Poll ID number of the last poll the user has voted in

intVotedIDNo = CInt(Request.Cookies("Poll")("PollID"))

'If the user has already voted then redirect them to the results page

If intVotedIDNo = intPollIDNum Then blnAlreadyVoted = True

End If

%>

<script  language="JavaScript">

<!-- Hide from older browsers...

//Function to open pop up window

function openWin(theURL,winName,features) {

  window.open(theURL,winName,features);

}

// -->

</script>

<form method="post" action="weekly_poll.asp" target="poll" onSubmit="window.open('', 'poll', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=460,height=400')">

  <table width="149" border="0" cellspacing="0" cellpadding="1" align="center">

    <tr>

      <td colspan="2"><font face="Arial, Helvetica, sans-serif" size="2">

        <% = strPollQuestion %>

        </font></td>

    </tr>

    <tr>

      <td>

        <%

'If there is a weekly poll to display then write the HTML to display it

If blnCheckForPoll = True Then

'Loop to display each of the selection choices for the poll

For intSelectionLoopCounter = 1 To 7

 

  'If there is a Selection choice then display the HTML to show it

  If NOT rsWeeklyPoll("Selection_" & intSelectionLoopCounter) = "" Then

 

  If blnAlreadyVoted = False Then 

    'Display a radio button for the selection choice

    Response.Write vbCrLf & " <tr><td><input type=""radio"" name=""PollVote"" value=""Votes_" & intSelectionLoopCounter & """>"

   

    'Display the selection choice

    Response.Write vbCrLf & " <font face=""Arial, Helvetica, sans-serif"" size=""1"">" & rsWeeklyPoll("Selection_" & intSelectionLoopCounter) & "</font></td></tr>"

   

  Else

 

    'If there are no votes yet then format the percent by 0 otherwise the sums corse problems

    If intToatalPollVotes = 0 Then

    dblPollVotePercentage = FormatPercent(0, 0)

   

    Else

    'Read in the the percentage of votes cast for the vote choice

    dblPollVotePercentage = FormatPercent((rsWeeklyPoll("Votes_" & intSelectionLoopCounter) / intToatalPollVotes), 0)

    End If

   

    'Display the selection choice results

    Response.Write vbCrLf & "        <tr>"

    Response.Write vbCrLf & "          <td colspan=""2""><font face=""Arial, Helvetica, sans-serif"" size=""1"">" & rsWeeklyPoll("Selection_" & intSelectionLoopCounter) & "</font></td>"

    Response.Write vbCrLf & "        </tr>"

    Response.Write vbCrLf & "        <tr>"

    Response.Write vbCrLf & "        <td width=""140""><img src=""bar_graph_image.gif"" width=""" & dblPollVotePercentage & """ height=""11""></td>"

    Response.Write vbCrLf & "        <td width=""9"" align=""right""><font face=""Arial, Helvetica, sans-serif"" size=""1"">" & dblPollVotePercentage & "</font></td>"

    Response.Write vbCrLf & "        </tr>"

 

  End If

  End If

Next

 

%>

      </td>

    </tr>

    <tr>

      <td align="center" colspan="2">

        <%

        'If the user has not voted then display a vote button

        If blnAlreadyVoted = False Then

        %>

        <input type="hidden" name="id" value="<% = intPollIDNum %>">

        <input type="submit" value="Vote" name="submit">

        <%

        'Display the totla number of votes

        Else

        'Display the total votes cast   

  Response.Write vbCrLf & "  <font face=""Arial, Helvetica, sans-serif"" size=""1"">Total Votes: " & intToatalPollVotes & "</font>"

End If

'Else if there is no weekly poll display the appropriate message

Else

Response.Write vbCrLf & "There is no Weekly Poll to display"

End If

'Reset Server Objects

Set adoCon = Nothing

rsWeeklyPoll.Close

Set rsWeeklyPoll = Nothing

     

%>

      </td>

    </tr>

    <tr>

      <td align="center" colspan="2"><a href="JavaScript:openWin('weekly_poll.asp?ID=<% = intPollIDNum %>','poll','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=460,height=400')"><font face="Arial, Helvetica, sans-serif" size="1">View

        Results</font></a></td>

    </tr>

  </table>

</form>

Link para o comentário
Compartilhar em outros sites

4 respostass a esta questão

Posts Recomendados

  • 0

Mano, confuso esse codigo.

Mas, se o esquema é não enviar cookies, então, procure pelo codigo onde diz:

Response.COOKIES

O modo de criar cookies em ASP é só assim

Link para o comentário
Compartilhar em outros sites

  • 0

já que você quer que seu cliente consiga votar varias vezes e não consegue achar aonde ele esta gravando o cookies altere aonde ele vai lê o cookies


'Check the user has not already voted by reading in a cookie from there system
'Read in the Poll ID number of the last poll the user has voted in
intVotedIDNo = CInt(Request.Cookies("Poll")("PollID"))

abraço

Link para o comentário
Compartilhar em outros sites

  • 0

procure a linha

If intVotedIDNo = intPollIDNum Then blnAlreadyVoted = True

subistitua por

If intVotedIDNo = intPollIDNum Then blnAlreadyVoted = False

pronto rolleyes.gif

imagino que deve funcionar

t+

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,3k
    • Posts
      652,3k
×
×
  • Criar Novo...