Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Pessoal bom dia! Minha enquete está exibindo a questão e as opções de voto, mas quando efetuo a votação dá erro. Alguém pode me ajudar? Seguem os CODES abaixo.
Ps:
bando de dados em MySql;
tabela: enquete;
colunas: Poll_ID, Poll_Question, Option_1, Option_2, Option_3, Option_4, Option_5, Votes_1, Votes_2, Votes_3, Votes_4, Votes_5, Status
enquete.asp
<!--#include file="conectar.asp"--><LINK href="../arquivos/style.css" type=text/css rel=stylesheet><script LANGUAGE=JavaScript><!--<!--function OptionChecked() { var i; for (i = 0; i < document.frmPoll.radPoll.length; i++) if (document.frmPoll.radPoll[i].checked) return true; alert("Você deve selecionar alguma opção"); return false; }// -->function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}}//--></SCRIPT><%'iniciar a seleçãoAbreConexaolistar = "SELECT * FROM enquete WHERE Status = 'Ativa' "Set lista = Conexao.Execute(listar)'Set RS = Server.CreateObject("ADODB.Recordset")'RS.Open strQuery, db, 3,3%><%strVoted = cstr(Request.Cookies("JCPoll"))if strVoted <> cstr(lista("poll_id")) then 'mostra a questao da enquete%> <title><%=lista("Poll_Question")%></title><body bgcolor="#A8A89E" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('bt_votar.gif','cinza.gif')"><table width="145" height="143" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="34"> <table width="145" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="4"> </td> <td width="116"><span class="texto"><%=lista("Poll_Question")%></span></td> </tr> </table></td> </tr> <tr> <td height="12"></td> </tr> <tr> <td><FORM METHOD=POST ACTION="votar.asp" ONSUBMIT="return OptionChecked();" NAME=frmPoll> <% for t = 1 to 5 VoteOption = "Option_" & t If lista(VoteOption) <> "" then %> <INPUT TYPE=RADIO NAME=radPoll VALUE="<%=t%>"> <span class="texto"><%=lista(VoteOption)%></span><BR> <% end if next 't %> <CENTER> <br> <br> <input name="imageField" type="image" src="bt_votar.gif" width="44" height="20" border="0"> </CENTER> </form></td> </tr></table> <%else 'mostra os resultados da enquete%><table width="145" height="203" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="27"> <table width="145" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="4"> </td> <td width="76"><span class="texto"><%=lista("Poll_Question")%></span></td> </tr> </table></td></tr> <tr> <td> <% TotalVotes = lista("Votes_1") + lista("Votes_2") + lista("Votes_3") + lista("Votes_4") + lista("Votes_5") %> <% for t = 1 to 5 VoteOption = "Option_" & t BarWidth = "Votes_" & t If lista(VoteOption) <> "" then %> <span class="texto"><%=lista(VoteOption)%> (<%=FormatPercent(lista(BarWidth)/TotalVotes)%>)</span> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0> <TR> <TD><img src = "cinza.gif" height="4" WIDTH=<%=CInt((lista(BarWidth)/TotalVotes)*150)%>> </TD> </TR> </TABLE> <% end if next 't %> <span class="texto">Total de Votos: <%=TotalVotes%></span> <% End Iflista.closeset lista = nothingFechaConexao%></td> </tr></table>
conectar.asp
<%Set Conexao = CreateObject("ADODB.CONNECTION")ConStr = "Driver={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=bd_site; UID=meulogin; PWD=minhasenha;" Conexao.CursorLocation = 3ConexaoAberta = FALSESub AbreConexao() if not ConexaoAberta then Conexao.Open ConStr ConexaoAberta = True end ifend subSub FechaConexao() if ConexaoAberta then Conexao.close ConexaoAberta = False end ifend sub %>
votar.asp
<!--#include file="conectar.asp"--><% @LANGUAGE = VBScript %><% if Request.Form("radpoll") = "" then response.redirect "enquete.asp"%><%'abre o bd para pegar informacoesAbreConexaolistar = "SELECT FROM enquete WHERE Status = 'Ativa' "Set lista = Conexao.Execute(listar)%><%POLLID = lista("Poll_ID") UserSelected = "Votes_" & Request.Form("radpoll")for t = 1 to 5VoteOption = "Votes_" & tif VoteOption = UserSelected then lista = "UPDATE enquete SET " & VoteOption & " = " & (lista(VoteOption) +1) &_ " WHERE Poll_ID = " & POLLID end ifnext 'tdb.execute ( lista )lista.closelistar = "SELECT FROM enquete WHERE Poll_ID = " & POLLID & ""lista.Open listarResponse.Cookies("JCPoll") = trim(POLLID)'Response.Cookies("JCPoll").Expires = objRS("End_Date")lista.closeset lista = nothing'db.close'set db = nothingFechaConexaoResponse.Redirect Request.ServerVariables("HTTP_REFERER")%>
Carregando comentários...