Lid |
|
ey
ik heb deze korte poll script, maar de fout is, je kant nog een tweede en derde en nog veel vaker stemmen, terwijl je eigelijk maar 1 keer MAG stemmen..., verder werkt alles goed
<?php
$vraag='Wat vind je van de site?';
$antwoord1='Goed';
$antwoord2='Redelijk';
$antwoord3='Slecht';
$dbh=mysql_connect ("localhost", "******", "******") or die ('Cant Connect To DB' . mysql_error());
mysql_select_db ("******");
function ip() {
if(getenv("HTTP_X_FORWARDED_FOR")) {
$IPadres = getenv("HTTP_X_FORWARDED_FOR");
} elseif(getenv("HTTP_CLIENT_IP")) {
$IPadres = getenv("HTTP_CLIENT_IP");
} else {
$IPadres = $_SERVER["REMOTE_ADDR"];
}
return $IPadres;
}
$IP=ip();
if(isset($_POST['submit']))
{
$queryinsert="INSERT INTO poll (ip, antwoord) VALUES ('$IP', '$antwoord')";
mysql_query($queryinsert) or die (mysql_error());
}
$query = "SELECT * FROM poll WHERE ip='$IP'";
$resultaat = mysql_query($query) or die ("Er is iets mis met de database");
$obj=mysql_fetch_object($resultaat);
if ($obj->ip < 1) {
echo "<form naam='poll' action='' method='POST'>
$vraag <br>
<input type='radio' name='antwoord' value='1'>$antwoord1<br>
<input type='radio' name='antwoord' value='2'>$antwoord2<br>
<input type='radio' name='antwoord' value='3'>$antwoord3<br>
<input type='submit' value='Stem!' name='submit'></form>";
} else {
$query = mysql_query("SELECT * FROM poll");
$row1 = mysql_query("SELECT * FROM poll WHERE antwoord='1' ");
$row2 = mysql_query("SELECT * FROM poll WHERE antwoord='2' ");
$row3 = mysql_query("SELECT * FROM poll WHERE antwoord='3' ");
//het totaal votes van de antwoorden
$total1 = mysql_num_rows($row1);
$total2 = mysql_num_rows($row2);
$total3 = mysql_num_rows($row3);
$total = $total1+$total2+$total3;
if ($total != 0)
{ $procent1a = round($total1 / $total * 100);
$procent2a = round($total2 / $total * 100);
$procent3a = round($total3 / $total * 100);
}
echo "$vraag<br>
$antwoord1:<img height=\"12\" alt=\"$total1 votes\" width=\"$procent1a\" src=\"poll-balk.gif\">$procent1a%<br>
$antwoord2:<img height=\"12\" alt=\"$total2 votes\" width=\"$procent2a\" src=\"poll-balk.gif\">$procent2a%<br>
$antwoord3:<img height=\"12\" alt=\"$total3 votes\" width=\"$procent3a\" src=\"poll-balk.gif\">$procent3a%<br>
Totaal: $total";
}
?>
<?php $vraag='Wat vind je van de site?'; $antwoord1='Goed'; $antwoord2='Redelijk'; $antwoord3='Slecht'; function ip() { if(getenv("HTTP_X_FORWARDED_FOR")) { $IPadres = getenv("HTTP_X_FORWARDED_FOR"); } elseif(getenv("HTTP_CLIENT_IP")) { $IPadres = getenv("HTTP_CLIENT_IP"); } else { $IPadres = $_SERVER["REMOTE_ADDR"]; } return $IPadres; } $IP=ip(); if(isset($_POST['submit'])) { $queryinsert="INSERT INTO poll (ip, antwoord) VALUES ('$IP', '$antwoord')"; } $query = "SELECT * FROM poll WHERE ip='$IP'"; $resultaat = mysql_query($query) or die ("Er is iets mis met de database"); if ($obj->ip < 1) { echo "<form naam='poll' action='' method='POST'> $vraag <br> <input type='radio' name='antwoord' value='1'>$antwoord1<br> <input type='radio' name='antwoord' value='2'>$antwoord2<br> <input type='radio' name='antwoord' value='3'>$antwoord3<br> <input type='submit' value='Stem!' name='submit'></form>"; } else { $row1 = mysql_query("SELECT * FROM poll WHERE antwoord='1' "); $row2 = mysql_query("SELECT * FROM poll WHERE antwoord='2' "); $row3 = mysql_query("SELECT * FROM poll WHERE antwoord='3' "); //het totaal votes van de antwoorden $total = $total1+$total2+$total3; if ($total != 0) { $procent1a = round($total1 / $total * 100); $procent2a = round($total2 / $total * 100); $procent3a = round($total3 / $total * 100); } $antwoord1:<img height=\"12\" alt=\"$total1 votes\" width=\"$procent1a\" src=\"poll-balk.gif\">$procent1a%<br> $antwoord2:<img height=\"12\" alt=\"$total2 votes\" width=\"$procent2a\" src=\"poll-balk.gif\">$procent2a%<br> $antwoord3:<img height=\"12\" alt=\"$total3 votes\" width=\"$procent3a\" src=\"poll-balk.gif\">$procent3a%<br> Totaal: $total"; } ?>
|