• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[Release] Website polling

Status
Not open for further replies.
Newbie Spellweaver
Joined
Sep 12, 2008
Messages
27
Reaction score
0
This script allows you to add a poll to your website.
  • 1 vote per IP
  • only registerd ingame users may vote
  • Displaies percent
  • Displaies % as a bar
  • Displays total vote
  • Displays total votes for each option
  • logs date
  • uses text imput
  • not hard to add more options
  • 2 choices default
http://www.mediafire.com/download.php?m211a4zg5em
Put pollimg inside of your images directory and the poll.php inside of your website.
To add it to a part of your website add
Code:
<?php include("poll.php"); ?>
to any where.
SQL
Code:
DROP TABLE IF EXISTS `voteTable`;
CREATE TABLE `voteTable` (
  `id` int(11) NOT NULL auto_increment,
  `choice1` tinyint(1) NOT NULL default '0',
  `choice2` tinyint(1) NOT NULL default '0',
  `hasvoted` tinyint(1) NOT NULL default '0',
  `ip` varchar(40) NOT NULL default '',
  `date` varchar(40) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Thanks for reading put your flame elsewhere.


Quick fix for blocking people who aren't registered...
Below
Code:
		$rCheck = mysql_query("SELECT * FROM `accounts` WHERE `lastknownip`='".$ipadress."'") or die(mysql_error());//checks if user is registerd ingame
Add
Code:
		$rCheck2= mysql_num_rows($rCheck);
Change
Code:
	}elseif($rCheck >= 1){
to
Code:
	}elseif($rCheck2 >= 1){

Sorry for that, if you need one you can just replace yours with the one below.
Code:
<?php
include("config.php");
/* Copy righted 2008 to Duncan Brown use with out concent is prohibited. */

   function tep_get_ip_address() {
     if (isset($_SERVER)) {
       if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
       } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
         $ip = $_SERVER['HTTP_CLIENT_IP'];
       } else {
         $ip = $_SERVER['REMOTE_ADDR'];
       }
     } else {
       if (getenv('HTTP_X_FORWARDED_FOR')) {
         $ip = getenv('HTTP_X_FORWARDED_FOR');
       } elseif (getenv('HTTP_CLIENT_IP')) {
         $ip = getenv('HTTP_CLIENT_IP');
       } else {
         $ip = getenv('REMOTE_ADDR');
       }
     }
 
    return $ip;
 }
 

		$aa1 = mysql_query("SELECT * FROM `votetable` WHERE `choice1`='1' AND `hasvoted`=1") or die(mysql_error());//counts choice 1	
		$aa2 = mysql_query("SELECT * FROM `votetable` WHERE `choice2`='1' AND `hasvoted`=1") or die(mysql_error());//counts choice 2

		$a1 = mysql_num_rows($aa1);
		$a2 = mysql_num_rows($aa2);
	
		$ipadress = tep_get_ip_address();
		
		$acheck = mysql_query("SELECT * FROM `votetable` WHERE `ip`='".$ipadress."'") or die(mysql_error());//checks in voted
		$acheck2 = mysql_num_rows($acheck);
		
		$ftotal1 = mysql_query("SELECT * FROM `votetable` WHERE `hasvoted`='1'") or die(mysql_error());//checks in voted
		$ftotal = mysql_num_rows($ftotal1);
		
		$findp1 = (int) (($a1/$ftotal)*100);
		$findp2 = (int) (($a2/$ftotal)*100);
		
		$gl1 = (int) (100-$findp1);
		$gl2 = (int) (100-$findp2);
		
if($acheck2 >= 1){
	echo "<fieldset><legend><b>Results</b></legend>";
	if($a1 >= 1){
		echo "<table width=\"286\" border=\"0\"><tr><th scope=\"row\">Whipe: ".$a1."</th><td>".$findp1."%</td>";
		echo "<td><img src=\"images/pollimg/bar.gif\" width=\".$findp1.\" height=\"11\"/><img src=\"images/pollimg/ghost.gif\" width=\".$gl1.\" height=\"11\"/><br><td>";
	}else{
		echo "<table width=\"286\" border=\"0\"><tr><th scope=\"row\">Whipe: 0";
		echo "<td><img src=\"images/pollimg/bar.gif\" width=\"1\" height=\"11\"/><img src=\"images/pollimg/ghost.gif\" width=\"99\" height=\"11\"/><br><td>";
	}
	if($a2 >= 1){
		echo "<tr><th scope=\"row\">Keep: ".$a2."</th><td>".$findp2."%</td>";
		echo "<td><img src=\"images/pollimg/bar.gif\" width=\".$findp2.\" height=\"11\"/><img src=\"images/pollimg/ghost.gif\" width=\".$gl2.\" height=\"11\"/><br><td></table>";
	}else{
		echo "<tr><th scope=\"row\">Keep: 0</th>";
		echo "<td><img src=\"images/pollimg/bar.gif\" width=\"1\" height=\"11\"/><img src=\"images/pollimg/ghost.gif\" width=\"99\" height=\"11\"/><br><td></table>";
	}
	echo "Total Votes: ".$ftotal."";
	echo "</fieldset>";
}else{
	if(!$_POST['vote']){
		echo "<fieldset><legend><b>To whipe or not to whipe that is the question!</b></legend><br />";
		echo "<form method=\"POST\">";
		echo "<center><table border=\"0\" width=\"20\">";
		echo "<tr><td align=\"left\" width=\"25%\"><b>Whipe or Keep Please enter one.</b></td><td><input type=\"text\" name=\"choice\" maxlength=\"12\"></td></tr>";
		echo "<tr><td></td><td><input type=\"submit\" value=\"Vote!\" name=\"vote\">";
		echo "</table></center></form>";
		echo "</fieldset>";
	}else{
		$bVote = mysql_query("SELECT * FROM `voteTable` WHERE `ip`='".$ipadress."'") or die(mysql_error());//checks in voted
		$rCheck = mysql_query("SELECT * FROM `accounts` WHERE `lastknownip`='".$ipadress."'") or die(mysql_error());//checks if user is registerd ingame
		$rCheck2= mysql_num_rows($rCheck);
		$choice = mysql_real_escape_string($_POST['choice']);
		$date = date("m/d/Y h:i");
		
	if($choice == ""){
			echo "Please supply an choice!";
	}elseif($acheck2 >= 1){
		echo "You have already voted cheater!!!";
	}elseif($rCheck2 >= 1){
	if($choice == "whipe" || $choice == "Whipe"){//cehcks for caps or not
			$ia = mysql_query("INSERT INTO `voteTable` (`choice1`,`hasvoted`,`ip`,`date`) VALUES ('1','1','".$ipadress."','".$date."')") or die(mysql_error());
			echo "You have chosen to have the characters whiped.";
	}
	if($choice == "keep" || $choice == "Keep"){//checks for caps or not
			echo "You have chosen to keep the characters as is.";
			$ia = mysql_query("INSERT INTO `voteTable` (`choice2`,`hasvoted`,`ip`,`date`) VALUES ('1','1','".$ipadress."','".$date."')") or die(mysql_error());
	}
	}else{
	echo "fail";
}
}
}
?>
 
Last edited:
Supreme Arcanarch
Loyal Member
Joined
Jul 21, 2008
Messages
969
Reaction score
1
Nice job. I'm adding this. Thanks dude :)
 
Banned
Banned
Joined
Sep 21, 2008
Messages
68
Reaction score
0
wow what a crap release, i mean its decent if you want to add another table to your mysql already
 
Newbie Spellweaver
Joined
Sep 12, 2008
Messages
27
Reaction score
0
wow what a crap release, i mean its decent if you want to add another table to your mysql already

Thanks for flaming another topic. Please GTFO as you are just a fagot who's parent's don't love him. Also for you smart people thanks for the positive feed back.
 
Banned
Banned
Joined
Sep 21, 2008
Messages
68
Reaction score
0
Thanks for flaming another topic. Please GTFO as you are just a fagot who's parent's don't love him. Also for you smart people thanks for the positive feed back.

Your a Special person, if you keep on adding tables to mysql, it slows down. Its common sense ^_^
 
Experienced Elementalist
Joined
Apr 6, 2008
Messages
296
Reaction score
3
That only works if u have a crappy computer mr candyman3333
 
Experienced Elementalist
Joined
Apr 6, 2008
Messages
296
Reaction score
3
Not me,
I have tons of tables and columns. Makes no difference...
genius o_O
 
Status
Not open for further replies.
Back
Top