Hello there,
Pardon my english, is my second !
I am having trouble with my poll, so i would like to ask you very kindly if you could help me. Poll is using mysql.
How can i prevent visitor from votting more than once. I have tried with cookie.
It gives me "Cant modify header...." Is is possible that i could do something with visitors IP address ?
Can you please help me with my CODE, give sample what i need to put.Thank you !!!
I have on beginning of php file this
<? if (!isset ($submit)) { //not press vote or result
Than it starts reads from mysql if there is any polls setup !
<?
$sel_poll = mysql_query("SELECT * from poll WHERE status='on'");
if (mysql_num_rows($sel_poll)>0){ // if no poll exist
$sel_nr = rand(0, mysql_num_rows($sel_poll)-1);
mysql_data_seek($sel_poll, $sel_nr);
$row_poll = mysql_fetch_array($sel_poll);
?>
<?
echo "<strong>$row_poll[1]</strong>";
?>
Than it starts to read from mysql for any answer !
<? for ($m=2;$m<=11;$m++){
if ($row_poll[$m] <> ""){ //if I have answer
?>
After all is satisfied pls. setup form for votting, and display !
<td><span class="style7">
<input name="vote" type="radio" value="<? echo $m;?>">
<? echo $row_poll[$m];?></span></td>
</tr>
<? }} ?>
<tr>
<td> <span class="style7">
<input name="idp" type="hidden" value="<? echo $row_poll[0] ?>">
<input type="submit" name="submit" value="Vote" class="butoanepoll">
<input type="submit" name="submit" value="Result" class="butoanepoll">
</span></td>
</tr>
</table>
</form>
<span class="style6">
If visitors votes, start writting to mysql table by adding new record.
<?
} //if no poll exist
}
if ($submit == "Vote") {
if ($vote ==2) $updres = mysql_query("UPDATE poll SET result1 = result1+1 WHERE idp = " . $idp);
if ($vote ==3) $updres = mysql_query("UPDATE poll SET result2 = result2+1 WHERE idp = " . $idp);
if ($vote ==4) $updres = mysql_query("UPDATE poll SET result3 = result3+1 WHERE idp = " . $idp);
if ($vote ==5) $updres = mysql_query("UPDATE poll SET result4 = result4+1 WHERE idp = " . $idp);
if ($vote ==6) $updres = mysql_query("UPDATE poll SET result5 = result5+1 WHERE idp = " . $idp);
if ($vote ==7) $updres = mysql_query("UPDATE poll SET result6 = result6+1 WHERE idp = " . $idp);
if ($vote ==8) $updres = mysql_query("UPDATE poll SET result7 = result7+1 WHERE idp = " . $idp);
if ($vote ==9) $updres = mysql_query("UPDATE poll SET result8 = result8+1 WHERE idp = " . $idp);
if ($vote ==10) $updres = mysql_query("UPDATE poll SET result9 = result9+1 WHERE idp = " . $idp);
if ($vote ==11) $updres = mysql_query("UPDATE poll SET result10 = result10+1 WHERE idp = " . $idp);
}//if submit=vote
?>
</span></TD>
</TR>
<TR class="style12">
<TD>
<?
//Display results from
$sql="SELECT * FROM poll WHERE idp = '$idp'";
$result = mysql_query($sql);
$row= mysql_fetch_array($result);
$total=$row[result1]+$row[result2]+$row[result3]+$row[result4]+$row[result5]+$row[result6]+$row[result7]+$row[result8]+$row[result9]+$row[result10];
//show ansers
echo "<table class=\"style7\">";
echo "<tr><td class=\"style7\" colspan=\"2\"><b>$row[1]</b></td></tr>";
for ($t=1;$t<=10;$t++){
$varib="answer".$t;
$varic="result".$t;
if ($row[$varic]<>0){
$proc=$row[$varic]/$total;
$proc=100*$proc;
$proc=number_format($proc, 2, '.', '');
$lung=1*round($proc);
}else{
$proc=0;
$lung=0;
}
if ($row[$varib]<>""){
echo "<tr>
<td class=\"style12\" width=\"50%\">$row[$varib]</td>
</tr><tr>
<td class=\"style12\" >";
if ($lung > 0){
echo "<img src=\"slike/leftbar.gif\" width=7><img src=\"slike/mainbar.gif\" width=\"$lung\" height=\"15\"><img src=\"slike/rightbar.gif\" width=7>";
}
echo " $proc% ($row[$varic])</td>
</tr>";
}
}
echo "</table>";
?>
I am very sorry for posting so much on this forum.
Thank you all for reading my post.