Easy Poll
Auteur: Deko - 27 september 2004 - 21:40 - Gekeurd door: Dennisvb - Hits: 21346 - Aantal punten: 2.22 (9 stemmen)
Dit is een poll die werkt met mysql. Iedere bezoeker kan maar één keer stemmen, helaas heb ik er wel geen admin systeempje bij gemaakt. Hieronder een schema welke MySQL tabellen je moet aanmaken, onderaan kun je de images voor de poll downloaden. Veel plezier ;)
Mysql tabellen:
CREATE TABLE poll (
vraag varchar (255) not null
)
CREATE TABLE poll_ant (
id int(10) auto_increment not null,
antwoord varchar(255) not null
primary key(id)
)
CREATE TABLE poll_ip (
id int(10) auto_increment not null,
ip varchar(20) not null,
poll_ant varchar(255) not null
primary key(id)
)
|
Code: |
PAGINA poll.php
<?php
include("db.php");
if (empty($_POST)){
/* locatie waar bezoeker doorgestuurt word als de pagina
geen POST variabelen heeft ontvangen */
header("Location: http://www.website.nl/");
}else{
$ip = $_SERVER['REMOTE_ADDR'];
// vul bij [ipbloktable] de tabel in waar de geblokte ip's in staan
$query = "SELECT * FROM [ipbloktable] WHERE ip='".$ip."'";
$result = mysql_query($query) or die ("FOUT: ".mysql_error());
$aantal = mysql_num_rows($result);
if ($aantal >= 1){
// wanneer de IP geblokt is naar dit adres doorsturen
header("Location: http://www.website.nl/");
}else{
$poll = $_POST["poll"];
$query = "INSERT INTO poll_ip (ip,poll_ant) VALUES ('$ip','$poll')";
mysql_query($query) or die ("FOUT: ".mysql_error());
}
}
?>
<?php include("db.php"); /* locatie waar bezoeker doorgestuurt word als de pagina geen POST variabelen heeft ontvangen */ header("Location: http://www.website.nl/"); }else{ $ip = $_SERVER['REMOTE_ADDR']; // vul bij [ipbloktable] de tabel in waar de geblokte ip's in staan $query = "SELECT * FROM [ipbloktable] WHERE ip='".$ip."'"; if ($aantal >= 1){ // wanneer de IP geblokt is naar dit adres doorsturen header("Location: http://www.website.nl/"); }else{ $poll = $_POST["poll"]; $query = "INSERT INTO poll_ip (ip,poll_ant) VALUES ('$ip','$poll')"; } } ?>
PAGINA index.php of andere
<?php
include("db.php");
$ip = $_SERVER['REMOTE_ADDR'];
$query = "SELECT * FROM poll_ip WHERE ip='".$ip."'";
$result = mysql_query($query) or die ("FOUT: ".mysql_error());
$aantal = mysql_num_rows($result);
if ($aantal == 0){
echo("<form action=\"poll.php\" method=\"post\">");
$query = "SELECT vraag FROM poll";
$result = mysql_query($query) or die ("FOUT: ".mysql_error());
$rij = mysql_fetch_assoc($result);
echo("<b>".$rij["vraag"]."</b><br>");
$query = "SELECT * FROM poll_ant ORDER BY id ASC";
$result = mysql_query($query) or die ("FOUT: ".mysql_error());
$teller = 1;
while ($rij = mysql_fetch_assoc($result)){
echo("<input type=\"radio\" name=\"poll\" value=\"".$teller."\" style=\"border : 0px;\">".$rij["antwoord"]."<br>");
$teller++;
}
echo("<input type=\"submit\" value=\"Stem!\"></form>");
}else{
$query = "SELECT * FROM poll_ant ORDER BY id ASC";
$result = mysql_query($query) or die ("FOUT: ".mysql_error());
$aantal = mysql_num_rows($result);
$teller = 1;
$query = "SELECT vraag FROM poll";
$result = mysql_query($query) or die ("FOUT: ".mysql_error());
$rij = mysql_fetch_assoc($result);
echo("<b>".$rij["vraag"]."</b><br>");
while ($teller <= $aantal){
$query = "SELECT * FROM poll_ant WHERE id='".$teller."' ORDER BY id ASC";
$result = mysql_query($query) or die ("FOUT: ".mysql_error());
$rij = mysql_fetch_assoc($result);
echo($rij["antwoord"]."<br><img src=\"poll_left.gif\" border=\"0\">");
$query = "SELECT * FROM poll_ip";
$result = mysql_query($query) or die ("FOUT: ".mysql_error());
$totaal_hoeveel = mysql_num_rows($result);
$query = "SELECT * FROM poll_ip WHERE poll_ant='".$teller."'";
$result = mysql_query($query) or die ("FOUT: ".mysql_error());
$ant_hoeveel = mysql_num_rows($result);
if ($ant_hoeveel != 0){
$nummer = $totaal_hoeveel / 100;
$nummer = $ant_hoeveel / $nummer;
}else{
$nummer = 0;
}
$procent = substr($nummer, 0, 5);
echo("<img src=\"poll_midden.gif\" border=\"0\" width=\"".$nummer."\" height=\"10\">");
echo("<img src=\"poll_right.gif\" border=\"0\"> ".$procent."%<br>");
$teller++;
}
$query = "SELECT * FROM poll_ip";
$result = mysql_query($query) or die ("FOUT: ".mysql_error());
$aantalstemmen = mysql_num_rows($result);
echo("<br>Stemmen: ".$aantalstemmen."<br>");
}
?>
<?php include("db.php"); $ip = $_SERVER['REMOTE_ADDR']; $query = "SELECT * FROM poll_ip WHERE ip='".$ip."'"; if ($aantal == 0){ echo("<form action=\"poll.php\" method=\"post\">"); $query = "SELECT vraag FROM poll"; echo("<b>".$rij["vraag"]."</b><br>"); $query = "SELECT * FROM poll_ant ORDER BY id ASC"; $teller = 1; echo("<input type=\"radio\" name=\"poll\" value=\"".$teller."\" style=\"border : 0px;\">".$rij["antwoord"]."<br>"); $teller++; } echo("<input type=\"submit\" value=\"Stem!\"></form>"); }else{ $query = "SELECT * FROM poll_ant ORDER BY id ASC"; $teller = 1; $query = "SELECT vraag FROM poll"; echo("<b>".$rij["vraag"]."</b><br>"); while ($teller <= $aantal){ $query = "SELECT * FROM poll_ant WHERE id='".$teller."' ORDER BY id ASC"; echo($rij["antwoord"]."<br><img src=\"poll_left.gif\" border=\"0\">"); $query = "SELECT * FROM poll_ip"; $query = "SELECT * FROM poll_ip WHERE poll_ant='".$teller."'"; if ($ant_hoeveel != 0){ $nummer = $totaal_hoeveel / 100; $nummer = $ant_hoeveel / $nummer; }else{ $nummer = 0; } $procent = substr($nummer, 0, 5); echo("<img src=\"poll_midden.gif\" border=\"0\" width=\"".$nummer."\" height=\"10\">"); echo("<img src=\"poll_right.gif\" border=\"0\"> ".$procent."%<br>"); $teller++; } $query = "SELECT * FROM poll_ip"; echo("<br>Stemmen: ".$aantalstemmen."<br>"); } ?>
Download code (.txt)
|
|
|
Stemmen |
Niet ingelogd. |
|