When you combine some neat functionality courtesy of PHP with the cleverness of jQuery you can produce some pretty cool results. In this tutorial we'll create a poll using PHP and XHTML, then make use of some jQuery Ajax effects to eliminate the need for a page refresh, and to give it a nice little bit of animation.
HTML
Let’s get our <head> set up:
<link href="style.css" rel="stylesheet" type="text/css" /> <script src="jquery.js" type="text/javascript" charset="utf-8"></script> <script src="jquery.cookie.js" type="text/javascript" charset="utf-8"></script> <script src="poll.js" type="text/javascript" charset="utf-8"></script>
- style.css will hold the CSS markup.
- jquery.js is the base jQuery library.
- jquery.cookie.js is a plugin by Klaus Hartl to add cookie manipulation to jQuery.
- poll.js will have the Javascript that makes the poll dynamic.
Next, we’ll create a simple poll form:

<div id="poll-container">
<h3>Poll</h3>
<form id='poll' action="poll.php" method="post" accept-charset="utf-8">
<p>Pick your favorite Javascript framework:</p>
<p><input type="radio" name="poll" value="opt1" id="opt1" /><label for='opt1'> jQuery</label><br />
<input type="radio" name="poll" value="opt2" id="opt2" /><label for='opt2'> Ext JS</label><br />
<input type="radio" name="poll" value="opt3" id="opt3" /><label for='opt3'> Dojo</label><br />
<input type="radio" name="poll" value="opt4" id="opt4" /><label for='opt4'> Prototype</label><br />
<input type="radio" name="poll" value="opt5" id="opt5" /><label for='opt5'> YUI</label><br />
<input type="radio" name="poll" value="opt6" id="opt6" /><label for='opt6'> mootools</label><br /><br />
<input type="submit" value="Vote →" /></p>
</form>
</div>
This form will be processed by the PHP for now, and when we get the Javascript running, by jQuery. The PHP and Javascript are designed to pull the option ID from the value tag. is just a HTML entity encoded space, and → is an arrow: →.
PHP
Introduction
If Javascript is disabled, the PHP will:
- Take GET/POST requests from the form
- Set/check a cookie
- Make sure the request is from a unique IP
- Store the vote in a flat file DB
- Return the results included with a HTML file
If Javascript is enabled, the PHP will:
- Take GET/POST requests from the Javascript
- Make sure the request is from a unique IP
- Store the vote in a flat file DB
- Return the results as JSON
For the flat file DB we will be using a package written by Luke Plant.
First, we need an array with the names and IDs of the poll options:
<?php $options[1] = 'jQuery'; $options[2] = 'Ext JS'; $options[3] = 'Dojo'; $options[4] = 'Prototype'; $options[5] = 'YUI'; $options[6] = 'mootools';
The flatfile package uses numbers for the column identifiers, so lets set some constants to convert those to names:
define('OPT_ID', 0);
define('OPT_TITLE', 1);
define('OPT_VOTES', 2);
When the form is submitted, PHP needs to know what file to insert the results into and return, so we set another constant:
define('HTML_FILE', 'index.html');
We need to include flatfile.php and initialize a database object:
require_once('flatfile.php');
$db = new Flatfile();
The flat files are just text files stored in the data directory:
$db->datadir = 'data/';
define('VOTE_DB', 'votes.txt');
define('IP_DB', 'ips.txt');
If we get a request with the poll parameter, it’s the static form, so we process it. If the request has a vote parameter in it, it’s a Ajax request. Otherwise, we just return the HTML_FILE.
if ($_GET['poll'] || $_POST['poll']) {
poll_submit();
}
else if ($_GET['vote'] || $_POST['vote']) {
poll_ajax();
}
else {
poll_default();
}
poll_default()
function poll_default() {
global $db;
$ip_result = $db->selectUnique(IP_DB, 0, $_SERVER['REMOTE_ADDR']);
if (!isset($_COOKIE['vote_id']) && empty($ip_result)) {
print file_get_contents(HTML_FILE);
}
else {
poll_return_results($_COOKIE['vote_id']);
}
}
poll_default() processes requests directly to the script with no valid GET/POST requests.
The global line makes the $db object available in the function’s scope.
The script tracks unique IPs to make sure you can only vote once, so we do a query to check whether it is in the DB:
$ip_result = $db->selectUnique(IP_DB, 0, $_SERVER['REMOTE_ADDR']);
If we don’t have a cookie and the IP query comes up empty, the client hasn’t voted yet, so we can just send the HTML file which contains the form. Otherwise, we just send the results:
if (!isset($_COOKIE['vote_id']) && empty($ip_result)) {
print file_get_contents(HTML_FILE);
}
else {
poll_return_results($_COOKIE['vote_id']);
}
poll_submit()
function poll_submit() {
global $db;
global $options;
$id = $_GET['poll'] || $_POST['poll'];
$id = str_replace("opt", '', $id);
$ip_result = $db->selectUnique(IP_DB, 0, $_SERVER['REMOTE_ADDR']);
if (!isset($_COOKIE['vote_id']) && empty($ip_result)) {
$row = $db->selectUnique(VOTE_DB, OPT_ID, $id);
if (!empty($row)) {
$ip[0] = $_SERVER['REMOTE_ADDR'];
$db->insert(IP_DB, $ip);
setcookie("vote_id", $id, time()+31556926);
$new_votes = $row[OPT_VOTES]+1;
$db->updateSetWhere(VOTE_DB, array(OPT_VOTES => $new_votes), new SimpleWhereClause(OPT_ID, '=', $id));
poll_return_results($id);
}
else if ($options[$id]) {
$ip[0] = $_SERVER['REMOTE_ADDR'];
$db->insert(IP_DB, $ip);
setcookie("vote_id", $id, time()+31556926);
$new_row[OPT_ID] = $id;
$new_row[OPT_TITLE] = $options[$id];
$new_row[OPT_VOTES] = 1;
$db->insert(VOTE_DB, $new_row);
poll_return_results($id);
}
}
else {
poll_return_results($id);
}
}
poll_submit() takes the form submission, checks if the client has already voted, and then updates the DB with the vote.
These lines get the selected option’s ID, and set $id to it:
$id = $_GET['poll'] || $_POST['poll'];
$id = str_replace("opt", '', $id);
We need to check whether the option is in the DB yet:
$row = $db->selectUnique(VOTE_DB, OPT_ID, $id);
If it is in the DB (result not empty), we need to run an updateSetWhere(). If it isn’t we need to do an insert():
if (!empty($row)) {
$new_votes = $row[OPT_VOTES]+1;
$db->updateSetWhere(VOTE_DB, array(OPT_VOTES => $new_votes), new SimpleWhereClause(OPT_ID, '=', $id));
poll_return_results($id);
}
else if ($options[$id]) {
$new_row[OPT_ID] = $id;
$new_row[OPT_TITLE] = $options[$id];
$new_row[OPT_VOTES] = 1;
$db->insert(VOTE_DB, $new_row);
poll_return_results($id);
}
Either way, we need to insert the IP into the DB, and set a cookie (expires in one year):
$ip[0] = $_SERVER['REMOTE_ADDR'];
$db->insert(IP_DB, $ip);
setcookie("vote_id", $id, time()+31556926);
poll_return_results()
function poll_return_results($id = NULL) {
global $db;
$html = file_get_contents(HTML_FILE);
$results_html = "<div id='poll-container'><div id='poll-results'><h3>Poll Results</h3>\n<dl class='graph'>\n";
$rows = $db->selectWhere(VOTE_DB,
new SimpleWhereClause(OPT_ID, "!=", 0), -1,
new OrderBy(OPT_VOTES, DESCENDING, INTEGER_COMPARISON));
foreach ($rows as $row) {
$total_votes = $row[OPT_VOTES]+$total_votes;
}
foreach ($rows as $row) {
$percent = round(($row[OPT_VOTES]/$total_votes)*100);
if (!$row[OPT_ID] == $id) {
$results_html .= "<dt class='bar-title'>". $row[OPT_TITLE] ."</dt><dd class='bar-container'><div id='bar". $row[OPT_ID] ."'style='width:$percent%;'> </div><strong>$percent%</strong></dd>\n";
}
else {
$results_html .= "<dt class='bar-title'>". $row[OPT_TITLE] ."</dt><dd class='bar-container'><div id='bar". $row[OPT_ID] ."' style='width:$percent%;background-color:#0066cc;'> </div><strong>$percent%</strong></dd>\n";
}
}
$results_html .= "</dl><p>Total Votes: ". $total_votes ."</p></div></div>\n";
$results_regex = '/<div id="poll-container">(.*?)<\/div>/s';
$return_html = preg_replace($results_regex, $results_html, $html);
print $return_html;
}
poll_return_results() generates the poll results, takes the HTML file, replaces the form with the results, and returns the file to the client.
First, lets grab the HTML file and set $html to it:
$html = file_get_contents(HTML_FILE);
Next, we start the results HTML structure:
$results_html = "<div id='poll-container'><div id='poll-results'><h3>Poll Results</h3>\n<dl class='graph'>\n";
To create the results HTML we need to get all the rows (options) from the DB sorted by number of votes:
$rows = $db->selectWhere(VOTE_DB, new SimpleWhereClause(OPT_ID, "!=", 0), -1, new OrderBy(OPT_VOTES, DESCENDING, INTEGER_COMPARISON));
We also need the total votes to calculate percentages:
foreach ($rows as $row) {
$total_votes = $row[OPT_VOTES]+$total_votes;
}
Next, we calculate the percentage of votes the current option has:
foreach ($rows as $row) {
$percent = round(($row[OPT_VOTES]/$total_votes)*100);
The HTML for the results will be a definition list (<dl>) styled with CSS to create bar graphs:
$results_html .= "<dt class='bar-title'>". $row[OPT_TITLE] ."</dt><dd class='bar-container'><div id='bar". $row[OPT_ID] ."'style='width:$percent%;'> </div><strong>$percent%</strong></dd>\n";
Also, we should check if the current option is the one the client voted for, and change the color:
if (!$row[OPT_ID] == $id) {
}
else {
$results_html .= "<dt class='bar-title'>". $row[OPT_TITLE] ."</dt><dd class='bar-container'><div id='bar". $row[OPT_ID] ."' style='width:$percent%;background-color:#0066cc;'> </div><strong>$percent%</strong></dd>\n";
}
Here, we add a total vote count and close the html tags:
$results_html .= "</dl><p>Total Votes: ". $total_votes ."</p></div></div>\n";
This is a regex that finds the poll-container <div>:
$results_regex = '/<div id="poll-container">(.*?)<\/div>/s';
The last step in this function is to replace the poll form with the results using the regex, and return the result:
$return_html = preg_replace($results_regex, $results_html, $html); print $return_html;
poll_ajax()
function poll_ajax() {
global $db;
global $options;
$id = $_GET['vote'] || $_POST['vote'];
$ip_result = $db->selectUnique(IP_DB, 0, $_SERVER['REMOTE_ADDR']);
if (empty($ip_result)) {
$ip[0] = $_SERVER['REMOTE_ADDR'];
$db->insert(IP_DB, $ip);
if ($id != 'none') {
$row = $db->selectUnique(VOTE_DB, OPT_ID, $id);
if (!empty($row)) {
$new_votes = $row[OPT_VOTES]+1;
$db->updateSetWhere(VOTE_DB, array(OPT_VOTES => $new_votes), new SimpleWhereClause(OPT_ID, '=', $id));
}
else if ($options[$id]) {
$new_row[OPT_ID] = $id;
$new_row[OPT_TITLE] = $options[$id];
$new_row[OPT_VOTES] = 1;
$db->insert(VOTE_DB, $new_row);
}
}
}
$rows = $db->selectWhere(VOTE_DB, new SimpleWhereClause(OPT_ID, "!=", 0), -1, new OrderBy(OPT_VOTES, DESCENDING, INTEGER_COMPARISON));
print json_encode($rows);
}
poll_ajax() takes a request from the Javascript, adds the vote to the DB, and returns the results as JSON.
There are a few lines of code that are different from poll_submit(). The first checks if the Javascript just wants the results, and no vote should be counted:
if ($id != 'none')
The other two lines select the whole DB and return it as JSON:
$rows = $db->selectWhere(VOTE_DB, new SimpleWhereClause(OPT_ID, "!=", 0), -1, new OrderBy(OPT_VOTES, DESCENDING, INTEGER_COMPARISON)); print json_encode($rows);
CSS
.graph {
width: 250px;
position: relative;
right: 30px;
}
.bar-title {
position: relative;
float: left;
width: 104px;
line-height: 20px;
margin-right: 17px;
font-weight: bold;
text-align: right;
}
.bar-container {
position: relative;
float: left;
width: 110px;
height: 10px;
margin: 0px 0px 15px;
}
.bar-container div {
background-color:#cc4400;
height: 20px;
}
.bar-container strong {
position: absolute;
right: -32px;
top: 0px;
overflow: hidden;
}
#poll-results p {
text-align: center;
}

This CSS styles the results returned by the PHP or Javascript.
- .graph styles the container for the bars, titles and percentages. The
widthwill be different for each site. - .bar-title styles the titles for the bar graphs.
- .bar-container styles the individual bar and percentage containers
- .bar-container div styles the div that the bar is applied to. To create the bars, a percentage
widthis set with PHP or Javascript. - .bar-container strong styles the percentage.
- #poll-results p styles the total votes.
Javascript
Introduction
The Javascript will intercept the submit button, send the vote with Ajax, and animate the results.
First, some global variables. You should recognize the first three from the PHP. votedID stores the ID of the option the client voted for.
var OPT_ID = 0; var OPT_TITLE = 1; var OPT_VOTES = 2; var votedID;
Now we need a jQuery ready function which runs when the page loads:
$(document).ready(function(){
Inside that function we register the handler for the vote button which will run formProcess when it is triggered:
$("#poll").submit(formProcess);
We also need to check if the results <div> exists, and animate the results if it does:
if ($("#poll-results").length > 0 ) {
animateResults();
}
If we have a cookie we should jump straight to generating the results because the user has already voted. To do that we need to get rid of the poll form, get the id from the cookie, grab the results from the PHP and pass them to loadResults().
if ($.cookie('vote_id'))
$("#poll-container").empty();
votedID = $.cookie('vote_id');
$.getJSON("poll.php?vote=none",loadResults);
}
formProcess()
function formProcess(event){
event.preventDefault();
var id = $("input[@name='poll']:checked").attr("value");
id = id.replace("opt",'');
$("#poll-container").fadeOut("slow",function(){
$(this).empty();
votedID = id;
$.getJSON("poll.php?vote="+id,loadResults);
$.cookie('vote_id', id, {expires: 365});
});
}
formProcess() is called by the submit event which passes it an event object. It prevents the form from doing a normal submit, checks/sets the cookies, runs an Ajax submit instead, then calls loadResults() to convert the results to HTML.
First, we need to prevent the default action (submitting the form):
event.preventDefault();
Next, we get the ID from the currently selected option:
var id = $("input[@name='poll']:checked").attr("value");
id = id.replace("opt",'');
input[@name='poll']:checked is a jQuery selector that selects a <input> with an attribute of name='poll' that is checked. attr("value") gets the value of the object which in our case is optn where n is the ID of the option.
Now that we have the ID, we can process it. To start, we fade out the poll form, and setup an anonymous function as a callback that is run when the fade is complete. Animations don’t pause the script, so weird things happen if you don’t do it this way.
$("#poll-container").fadeOut("slow",function(){
After it has faded out we can delete the form from the DOM using empty():
$(this).empty();
In this case, $(this) is jQuery shorthand for the DOM element that the fade was applied to.
jQuery has some other shortcut functions, including $.getJSON() which does GET request for a JSON object. When we have the object, we call loadResults() with it:
$.getJSON("poll.php?vote="+id,loadResults);
The last thing to do is set the cookie:
$.cookie('vote_id', id, {expires: 365});
loadResults()
function loadResults(data) {
var total_votes = 0;
var percent;
for (id in data) {
total_votes = total_votes+parseInt(data[id][OPT_VOTES]);
}
var results_html = "<div id='poll-results'><h3>Poll Results</h3>\n<dl class='graph'>\n";
for (id in data) {
percent = Math.round((parseInt(data[id][OPT_VOTES])/parseInt(total_votes))*100);
if (data[id][OPT_ID] !== votedID) {
results_html = results_html+"<dt class='bar-title'>"+data[id][OPT_TITLE]+"</dt><dd class='bar-container'><div id='bar"+data[id][OPT_ID]+"'style='width:0%;'> </div><strong>"+percent+"%</strong></dd>\n";
} else {
results_html = results_html+"<dt class='bar-title'>"+data[id][OPT_TITLE]+"</dt><dd class='bar-container'><div id='bar"+data[id][OPT_ID]+"'style='width:0%;background-color:#0066cc;'> </div><strong>"+percent+"%</strong></dd>\n";
}
}
results_html = results_html+"</dl><p>Total Votes: "+total_votes+"</p></div>\n";
$("#poll-container").append(results_html).fadeIn("slow",function(){
animateResults();});
}
loadResults() is called by $.getJSON() and is passed a JSON object containing the results DB. It is pretty much the same as it’s PHP counterpart poll_return_results() with a few exceptions. The first difference is that we set the width on all the bars to 0% because we will be animating them. The other difference is that we are using a jQuery append() instead of regex to show the results. After the results fade in, the function calls animateResults().
animateResults()
function animateResults(){
$("#poll-results div").each(function(){
var percentage = $(this).next().text();
$(this).css({width: "0%"}).animate({
width: percentage}, 'slow');
});
}
animateResults() iterates through each of the bars and animates the width property based on the percentage.
each() is a jQuery function that iterates through each element that is selected:
$("#poll-results div").each(function(){
First, we set the percentage to the text of the element next to the bar which is the <strong> containing the percentage.
var percentage = $(this).next().text();
Then we make sure the width is set to 0%, and animate it:
$(this).css({width: "0%"}).animate({
width: percentage}, 'slow');
Related Posts
Check out some more great tutorials and articles that you might like
Plus Members
Source Files, Bonus Tutorials and
More for $9 a month for all TUTS+
sites in one subscription.












User Comments
( ADD YOURS )Hairudy July 23rd
Wow…great bro…
( )thanks…
Bhaarat July 23rd
I am first and this article just kicked major ass. I am not a fan of php so I am going to do this via struts2 and jsp. but the concept was awesome.
I look forward to every article in NETUTS!!
( )pavs July 23rd
The end result looks really neat.
Even though I understand the main goal of this tuts is to make us understand, how to do it and a look at under the hood; but it seems a little bit too much work a poll.
Anyone knows and good wordpress poll plugin out there?
I have a suggestion for a future tut, using jquery plugin jCarousel, to make sliders. Very interesting stuff.
Thanks
( )Bruce Alrighty July 23rd
Very Nice!
( )Nate July 23rd
Sweetness…
( )Mad-Hatter July 23rd
brilliant article mate, nice use of OOP in the PHP script excellent job! I hope to see more Jquery integration tutorials with PHP in the future!
( )Braden Keith July 23rd
Nice effect
( )Jbcarey July 24th
Okay, I like the result, but I think a little more explanation in between the step’s is neccesary…
( )Alex Coleman July 24th
Awesome…will definitely come in handy. A bit difficult to grasp every detail, but that’s just the nature of the beast.
( )Shane July 24th
nice transitions on the demo – thanks for posting. I’m typically a C# .NET developer (but I use a lot of jQuery).
Always wanting to learn more PHP – so thanks for this.
( )Lamin Barrow July 24th
Great article.. what i love about it is that it is not based on some wordpress plugin or something. Thanks.
( )Ben Griffiths July 24th
This is really good, and doesn’t need a massive amount of code either – thanks
( )Another Blog July 24th
Really nice, we need to see more of these tutorials at net tuts! We are unternurished unlike those over at PSDTUTS and VECTORTUTS!
Andrew
( )Mark Abucayon July 24th
wow awesome, exactly I am searching example poll now I think I will used this one later. Really nice I like it very much. Thank you for sharing this one
( )Daniel July 24th
very useful tutorial ! thanks so much! keep up the good work.
( )Sebastian July 24th
awesome work, but whatever i do it still shows me the SAME results! =(
( )Bryn June 19th
exactly! why is this does anyone know?
( )jeeremie July 24th
Wow! I love Nettuts. It is so easy to go through your tutorials here. And besides, all the scripts you create are so useful. I wish I had read this article yesterday as I was looking for inserting a poll on my blog. Too late, that’s done. But thanks anyway.
( )BeyondRandom July 24th
you cant see me…but im bowing down right lol…as usual, thanks alot!
( )Javier Tapia July 24th
¡¡awesome tutorial!! thanks
( )Taylor Satula July 24th
The submit button and radio buttons should be styled.
But besides that very nice
( )Michael Thompson July 24th
@Lamin Barrow: Yes, thank god. Wordpress is far from the only web technology worth writing tutorials about.
( )Ty July 24th
I downloaded the Source file and placed it in my Aptana Studio setup.
( )It’s not returning the results, in my local IDE setup then, wondering what may need tweaked so the results will return?
Maybe placed on an actual web server it would of worked no fuss, I’m kind of new with Aptana.
Thanks,
Ty
Ty July 24th
Nevermind, sorry for the dumb question, I haven’t fully setup my Aptana Studio setup by adding a Xampp server:
Introduction
Currently, to preview PHP pages and have them rendered appropriately, you will need to set up an external web server, such as XAMPP, and use that web server to render your PHP.
You can download XAMPP from the following web site:
http://www.apachefriends.org/en/xampp.html
Duh… OK Xampp is the way to go, I already know that.
( )Ad Manager July 24th
Wow, I tried the demo and it’s indeed elegant and simple.
( )calvin July 24th
jquery has dominated nettuts over the last couple weeks, and i couldn’t be happier. it’s such a great tool for designers, thanks so much guys!
( )Andrew July 24th
This is the second time this week nettuts wrote an article about a feature i was trying to add. Awesome stuff!
( )Jonathan July 24th
This is great. Didn’t grasp every detail on my first read through, so will have to come back for a more in depth look – but, it looks solid and will come in handy as I hate plugins.
( )Eric July 24th
Really nice job, Jonathan thanks alot
( )The Frosty July 24th
Woow.. JQuery pros? whats up?
I might have to start stopping by this site more often!
( )Faraz July 25th
¡awesome tutorial!! thanks
( )pavs July 26th
As much as I hate to say this, converting this to wordpress plugin would have been so sweet.
( )Accelebrate July 29th
I’m having trouble installing this on my own server, I’ve copied all the files over and changed permission where I deemed necessary. The poll with radio buttons appears, I click on vote and it fades out nicely only to be replaced by nothing rather than the poll results. Stays that way until I delete the cookie and then the radio buttons just show again.
Have I missed a setting or something?
( )Accelebrate July 29th
Closer inspection reveals an error…
Fatal error: Call to undefined function: json_encode() in poll.php on line 64
( )Nik July 29th
Just found it. This is exactly what I needed for a project of mine. Haven’t try it, but look neat and beautiful.
Thanks indeed!
( )andol July 30th
oh, awesome work~
( )packing all the js,css,html and php code into a baggage example would be better.
nicken July 30th
Exactly what I am looking for.
However: I was having similar issues to Accelebrate, until I played around with permissions.
Now I am getting the same problem as Sebastian… the results aren’t changing.
( )Ryan July 31st
I really like how the demo works.
I downloaded the code and tried to get it to work on my web server, and I seem to have the same problems as the people above. I changed the write permissions on votes.txt and ips.txt, but I still cannot get the votes to register.
I haven’t had the time to go through and study the code yet. Some instructions for installation would be helpful. Has anybody been successful getting this to work?
( )Ryan July 31st
Actually, now that I look at the demo…. it’s not working properly either. It’s not registering any votes. Can anyone troubleshoot this?
( )Jonathan August 2nd
I am having the same problem on my setup. I get the poll, select a selector and then fades to a blank screen. I don’t program (a designer only) but I chmod all files to 755 and even took it straight out of the zip, same results, I get a blank screen instead of the polling data!
I think the script is awesome (as demoed) and really would like to add it to my design arsenal.
Thanks in advance for any help you can give!
Jonathan
P. S. The script is located at http://www.adeeperfaith.com/inc/poll
( )Jonathan August 2nd
I should have said “the same problem as accelabrate” (smile)
( )Connor August 3rd
That’s a nice effect
( )STK August 4th
i have to say that i have the same problem as mentioned above … what permissions should i set to store the poll data in the txt file? awesome script anyway …
would implement it in my new project so please help
( )Jonathan Rudenberg August 4th
If you are having issues with the script please make sure you are running PHP 5.2.x, as it is not tested with PHP 4.
( )STK August 5th
thank you for the hint. the version of my php ist 5.2.6 so it should work, but it don’t save the the data in the txt file – any other idea? … am i the only one where the script don’t run?
( )MyTivu - Free Video Site August 6th
Great script. Will find a great use for it.
( )Taylor Satula August 6th
I dont do many polls but still this is helpful
( )Ted August 7th
First, great tutorial, best that ive seen by far.
Second
Im in the same situation as STK. I have php 5.2.6 on he server. And when one votes, the data stays the same, when i went to the txt file to clear the votes, and then votes again, it did not records my vote.
any help, or pointing me to the right direction,
greatly appreciated!
( )Nathan August 11th
For people having issues. I tried the demo on a server with php version 5.2.5 and another running 5.2.6. Runs great on the 5.2.5 server, but 5.2.6 is not returning results. I’ll post again if I find a solution.
( )Ward August 13th
For people having problems a couple of things
* turn off error reporting – error_reporting(0); in poll.php
* make sure to add write permissions on the directory and files that you are writing to in the flatfile application
* add ?> to the end of the poll.php file
* // quote these indexes in flatfile.php line 44 so they will stop triggering error notices
$comparison_type_for_col_type = array(
“INT_COL” => INTEGER_COMPARISON,
“DATE_COL” => INTEGER_COMPARISON, // assume Unix timestamps
“STRING_COL” => STRING_COMPARISON,
“FLOAT_COL” => NUMERIC_COMPARISON
);
If you are voting and the form fades out and nothing comes back it is likely contaminating the json form results response with error notices and the the js doesnt know what to do with the response – so turn off error reporting in poll.php. The rest of the problems appear to be with writing to the flatfile votes.txt, the ip recording works fine but no results are being recorded in the votes.txt. I’ll have to look at it some more.
( )Ward August 14th
Ok, in poll.php also change line 41 from $id = $_GET['poll'] || $_POST['poll']; to $id = $_GET['vote'];
this logic is also on line 76 so I imagine it will probly fail there as well and should be changed. I am not sure why its written that way. Maybe in some circumstances the js switches from using a get to a post? It could be rewritten like this
isset($_POST['poll']) ? $id = $_POST['poll'] : $id = $_GET['poll'];
as a fallback in case of post vars, you will probly want to verify that post as well as get is working.
( )Joe August 17th
Great script but my question is why someone would post a this polling solution without making sure it works!
( )rina August 18th
cool! i like it! thanks!
( )Petter August 20th
So bad PHP code I would say, that is for peoples for new to php?
( )I like the code but I’ve worked with PHP for a longer time now.
I would say that peoples that are new to PHP maybe not understand classes so good.
Kevin August 20th
Has anyone been able to get the poll to increment in the votes.txt? Everything seems to be working well for me except the poll incrementing numbers.
( )hoverMN August 21st
Same problem here ! please any body solve this…the vote is not registered….
( )ROTOR August 29th
The vote is not counted…it remains same…
why such bothering…please make the script working….Many of us are facing same problem
Why don’t you reply…please
( )leo.china September 8th
thanks !
( )gaijun September 8th
good
( )slackware September 8th
having the same probelm ,return a blank page
( )Tuomis September 25th
nice script thanx
( )Aaron September 27th
I’m having the same problems as everyone else. After clicking on the vote button the poll fades out with no results. I get a blank screen.
I don’t get why there isn’t more explanation for this tutorial and especially why this was posted incomplete.
If anyone has figured this out, I would love to know how to fix this problem. ..too much time has been wasted already. Thanks.
( )Andrew October 2nd
For everyone out there uploading this thing and having the votes not logged:
Replace:
$id = $_GET['vote'] || $_POST['vote'];
With:
$id = isset($_GET['vote']) ? $_GET['vote'] : $_POST['vote'];
and
Replace:
( )$id = $_GET['poll'] || $_POST['poll'];
With:
$id = isset($_GET['poll']) ? $_GET['poll'] : $_POST['poll'];
Sven October 3rd
Great article!
I just installed on my web server. I did all the alterations from the comment but:
The poll is not working! The results are not written in votes.txt!
( )Please, this is pointless if the results are not updated!
Sven October 5th
Don’t know what happened, but it’s working now!
There are two new files in the directory /data
ips.txt.lock
votes.txt.lock
Thanks!
( )orlando October 9th
Hi thanks for the article man, just one question, perhaps is because I’m more than a graphic designer and know much about php, but how could I use this but instead of one question I made a poll with several questions and multiple answers what changes I would have to do to the code to work with that?
( )jdzzle October 17th
wow, that’s a lot of crap for a stupid poll…
here’s mine..
DB Tables:
question(id,content,displayed)
option(id,question_id,content)
vote(id,question_id,option_id)
then just simple forms for the vote…
( )Mike March 18th
Exactly! But I think Jonathan was trying to avoid a whole section on MySql and Php database interaction. Should write a tut for that and submit, this is by far the most incomplete, faulty tutorial on the Envato network lol.
Guys! Fix it!!
( )ML October 19th
Cant get it to register the votes still..
Changed the PHP Code & the file permissions..
Anyone?
http://www.applesvbananas.com/demo
( )Christian October 21st
Not working, the results no written in file votes.txt, and i only see results even my ip not in ips.txt
Somebody help us!!!
( )Christian October 21st
I made a modification… i hope you can use it:
-delete al files in /data leave the sistem create it
( )-delete cookies in your browser.
-Voila!, it works.
amanda October 25th
Annoying that my comment choked. I meant to say that if you’re using firefox, you can actually delete only your “vote_id” cookie. If you know it is called vote_id, anyway. And you can also change poll.php to add a lot less than a year to your cookie, so that you can re-use the script.
( )faaliyet October 30th
Hi amanda
Can you help me? I have the same problem (with FF cookies).
I can’t rate a new poll in FF. What I should do ?
Thanks.
( )faaliyet
amanda October 26th
Soooo, ips.txt is being written but votes.txt isn’t. This is what I see in my error logs:
[Sun Oct 26 12:34:16 2008] [error] [client xx.xxx.xx.xxx] PHP Warning: fopen(data/essaycontest_ips.txt.lock) [function.fopen]: failed to open stream: Permission denied in /var/www/html/scripts/poll/flatfile.php on line 181, referer: http://www.example.com/scripts/poll/poll.html
( )[Sun Oct 26 12:34:16 2008] [error] [client xx.xxx.xx.xxx] PHP Warning: flock() expects parameter 1 to be resource, boolean given in /var/www/html/scripts/poll/flatfile.php on line 182, referer: http://www.example.com/scripts/poll/poll.html
[Sun Oct 26 12:34:16 2008] [error] [client xx.xxx.xx.xxx] PHP Warning: fwrite(): supplied argument is not a valid stream resource in /var/www/html/scripts/poll/flatfile.php on line 353, referer: http://www.example.com/scripts/poll/poll.html
[Sun Oct 26 12:34:16 2008] [error] [client xx.xxx.xx.xxx] PHP Warning: fclose(): supplied argument is not a valid stream resource in /var/www/html/scripts/poll/flatfile.php on line 354, referer: http://www.example.com/scripts/poll/poll.html
Rinat October 27th
Nice… but
( )try to sum up all vote results in %, you won’t get a 100% its just a 99%
why so?
monaye November 12th
Mnnn. Even demo is not working….
( )lyndon November 14th
ang galing…
( )kareem November 25th
this is wonderful tutorial i will put acopy of this lesson on
( )my site here
http://www.as7ap4you.com
dimi December 9th
My results are not being recorded. Anyone else? ideas?
( )CRINCH December 11th
I have put this code on my local system with wamp 1.6.5. I have same problem blank results page but there is ip and vote are being written in txt files. I have also put the above troubleshooting ways but in vain.
what can be the solution.
( )CRINCH December 11th
return key.replace(”-”, “+”).replace(”_”, “/”);
( )I am also facing this error ‘key is null’ in firefox. sorry to put this on the above post.
amy December 16th
the number of votes gets stuck on 53….apart from that its awsome….has anyone managed to get it working/???
( )luchtpost December 18th
Is it possible to store everything in a database instead of in a flat file? It should be easier to adapt the poll questions/answers. Maybe a tip for the next edition? I like the poll very much!
( )oha December 19th
ffs someone fix this script
( )nicholas December 22nd
The problem is the php framework, i tested it in two diferent servers… and just works fine with xampp installation
( )nick December 23rd
its not working for me unfortunately, the results aren’t updating.
help!
( )agus (Indonesia) December 23rd
very2 nice… keep developt it
( )Andreas December 28th
It works fine if you make the changes Andrew mentioned above.
( )You can see it in action on http://www.freelanceoverviews.com
php人 January 17th
不错,非常好用
( )Sumit January 19th
I really like the look of it, but the fact that the vote is not being recorded is really bothering me a lot…..has anyone come up with a solution to this…
( )jared January 20th
OK, I take that back. Things are still being screwy.
Ditch this script until someone with PHP knowledge actually updates it. It’s too flaky right now.
( )Cool January 22nd
Thanks bro. i liked
( )barukun January 24th
I’m trying to insert these code to a dynamic web as a module, it didn’t work because the method of displaying the results is overriding the in output html
( )Zargam February 4th
Im crying ….how lovely the tutorial was!
hehe
superb!
( )Elma Krom February 6th
Very good. I will try it my site. If have any problem I will contect with you.
( )Shannon February 12th
Works great once I followed this suggestion from above:
Ok, in poll.php also change line 41 from $id = $_GET['poll'] || $_POST['poll']; to $id = $_GET['vote'];
this logic is also on line 76 so I imagine it will probly fail there as well and should be changed. I am not sure why its written that way. Maybe in some circumstances the js switches from using a get to a post? It could be rewritten like this
isset($_POST['poll']) ? $id = $_POST['poll'] : $id = $_GET['poll'];
Don’t forget it logs your IP so if you are testing to make sure it’s recording the votes, delete your ip from the txt file and try again.
( )chief February 14th
OK THIS WILL NOT WORK LOCALLY.
I had the same problems as everyone else where the text files were not reflecting the vote. I added the %> to the bottom of the poll.php file and then uploaded all files to godaddy. You should create the data file folder and set the folder permissions to allow writing, but YOU SHOULD NOT COPY THE TEXT FILES. Let the program create the text files itself.
( )gencho February 15th
Poorly written code …
( )Gökhan February 15th
firstly thanks
Does anybody know How can we use this script with mysql database?
( )The Willer February 17th
Very cool, but the percentage sometimes is displayed wrong – it’s 101%. In php Mode you shoud do
( )$percent = round(number_format((($row['votes_count'] / $totalVotes) * 100), 2), 1);
mirel February 22nd
I really think that you should consider building an extension for joomla. I would if I could.
Anyone can help to “hard” integrate this on my left joomla position?
( )hi March 11th
not running.
not change db field.
( )Keegan March 12th
For those who have the working version, please post a zip with working code please? Its an awesome script….would love to implement into a project im working on.
( )Martin March 19th
I’ve come across something strange, I have access to two different servers, both running PHP 5.2.6. The Jquery Poll works fine on one server but just goes blank on the other!
Does anyone know why this is?
I updated poll.php with Andrews code ie:
For everyone out there uploading this thing and having the votes not logged:
Replace:
$id = $_GET['vote'] || $_POST['vote'];
With:
$id = isset($_GET['vote']) ? $_GET['vote'] : $_POST['vote'];
and
Replace:
$id = $_GET['poll'] || $_POST['poll'];
With:
$id = isset($_GET['poll']) ? $_GET['poll'] : $_POST['poll'];
Ward says:
* turn off error reporting – error_reporting(0); in poll.php
I cannot find error_reporting on poll.php at all.
This is such a cool script, can someone help?
Cheers
( )Phil March 20th
That error reporting line isn’t in the code thats why you can’t find it.
You want to copy that line “error_reporting(0);” into your poll.php page, I use “error_reporting(E_ALL ^ E_NOTICE);” to do the same job.
The server I’m trying it on is running PHP 5.2.6, I’ve made the changes suggested but with no luck.
I deleted the files from the data directory, then when I test it creates the ip.txt file but not the votes.txt file. I’m currently at a loss why it won’t create the votes file or write to it when its there.
( )Nik March 22nd
was this code ever working? Look at the top of the page where the image is…the total number of votes is 53!
( )Martin March 23rd
I put the line:
error_reporting(E_ALL ^ E_NOTICE);
at the top of poll.php after the <?php but it made no difference it still doesn’t work.
Om the server that I can get it to work if I update the poll.php script with Andrews code that I mentioned on my March 19th comment above I can get the poll to update the votes!
I still cannot get the poll to work on my other server which is running the same version of php and I just cannot figure out why so someone please help – would it be one php 5.2.6 has a slightly different configuration? something turned off when it should be on?
When I submit the vote the script fades to a blank page and the bottom line flickers like mad and the only way I can get it to stop flickering is when I play around with line 64 on poll.php which is:
print json_encode($rows);
so this maybe a clue but I am not a php or json script expert!
( )Martin March 25th
HOW TO FIX THE POLL AND GET IT WORKING!
Ok, I’ve sorted it with the help from Andrew (above) and my ISP.
Firstly download the source code from this page.
Secondly in poll.php:
Replace: $id = $_GET['vote'] || $_POST['vote']; With: $id = isset($_GET['vote']) ? $_GET['vote'] : $_POST['vote'];
and
Replace: $id = $_GET['poll'] || $_POST['poll']; With: $id = isset($_GET['poll']) ? $_GET['poll'] : $_POST['poll'];
and the final secret to get the poll to work is to disable the “mod_security rule”. If you cannot do it yourself you will need to ask your service provider!
That’s it, it works fine. If you want to keep testing it just download the ips.txt file, delete your IP number, re-upload and test again, you will see the votes counting everytime you do this. DO NOT touch the votes.txt file as this counts the votes!
( )Yegor March 26th
Do you have any more info on what mod_security rule needs to be disabled…?
( )Martin March 26th
No I am afraid I don’t as my ISP did it their end for me. I’m not sure what the implications of disabling the mod_security is and indeed WHY it needs disabling just for a poll to work!
( )Phil March 27th
I tried editing my .htaccess file and added this line of code:
SecFilterEngine Off
This apparently will turn mod_security off, but when I test my page I then have 500 internal server error… which takes me back to square one.
Its such a nice dynamic poll its a shame that I can’t get it to work. I expect I could fiddle it to work off mysql but having never come across flatfile.php before I wanted to do it this way.
( )Phil March 27th
From my understanding, mod_security is essentually a screen or a firewall that protects your web server from attacks.
( )Robbie March 29th
Does anybody know how I can make the poll dynamic so that I can change the poll weekly and restart the count & percentages?
( )Thanks in advance…
DekuLink March 29th
I’ve followed everything, but it still shows the results of the default poll. And when I vote, the stats don’t change. How do I reset the votes and let it write to the votes.txt file?
( )Martin March 31st
Try to eliminate “event.preventDefault();” in function formProcess(event) in poll.js
I think it will answer your questions guys
( )Martin March 31st
sorry .. little mistake..
( )Magnus April 3rd
how can I convert the whole thing with jquery.noconflict?
it acts up in combination with mootools smoothgallery
( )Muhammed Ashraf CK April 8th
Wow its great!!!!!!!!!!!
( )I have a doubt that How can we return to the index.html for new poll
Kaka April 12th
Great, i love it. But i dont know How it can work with some polls when i connect to database in mysql.
( )Some one help, please
omar April 14th
Hello ,
( )really, this is a great poll
thanks alot ..
pease can you tell us what’s the variables should be changed to work on mysql databases?
I mean the main variables of polls,ips,questions,results and numbers ..etc?
Guillermo Trejo May 4th
Hi everybody. I know this is an old post and also I know this is only for leaving a comment (is no a forum), but I really need everybody’s help.
This tool-script-tutorial is the perfecto solution for my client’s site problem, the only question is: What about if I want to include 10 different questions and, at the end of the poll (or should I now call it quiz) return the results the way it does.
thanks everbody for your time and for any kind of advice.
( )Majid May 7th
Hi,
I tried this nice script it’s working, I am a java developer, I am thinking to start learning php too.
Yes the pool is working but I got some warning errors :
Warning: fopen(data/ips.txt.lock) [function.fopen]: failed to open stream: Permission denied in /var/www/pool/flatfile.php on line 181
Warning: flock() expects parameter 1 to be resource, boolean given in /var/www/pool/flatfile.php on line 182
Warning: fwrite(): supplied argument is not a valid stream resource in /var/www/pool/flatfile.php on line 353
Warning: fclose(): supplied argument is not a valid stream resource in /var/www/pool/flatfile.php on line 354
Warning: flock() expects parameter 1 to be resource, boolean given in /var/www/pool/flatfile.php on line 194
Warning: Cannot modify header information – headers already sent by (output started at /var/www/pool/flatfile.php:181) in /var/www/pool/poll.php on line 84
Warning: fopen(data/votes.txt.lock) [function.fopen]: failed to open stream: Permission denied in /var/www/pool/flatfile.php on line 181
Warning: flock() expects parameter 1 to be resource, boolean given in /var/www/pool/flatfile.php on line 182
Warning: fwrite(): supplied argument is not a valid stream resource in /var/www/pool/flatfile.php on line 353
Warning: fclose(): supplied argument is not a valid stream resource in /var/www/pool/flatfile.php on line 354
Warning: flock() expects parameter 1 to be resource, boolean given in /var/www/pool/flatfile.php on line 194
Can you please help.
thanks, your help is appreciated.
Majid
( )DevNull July 9th
You need to set write permissions on your data directory so that the web server user can write to the database files
$find [PATH TO DATA] -type f -exec chmod 0666 {} \;
( )$chmod 0777 [PATH TO DATA]
Darren May 9th
very good
( )杠杠的。
Thom May 12th
Came across this script and thought that it was amazing… until I tried to install it. Managed to get the results showing once I made the changes listed above. But I could never get my new votes or IP address recorded despite using all the methods mentioned about.
Better luck next time.
( )Kevin May 14th
this is not really cool!!!… i can’t change anything in the code!
( )Scott May 18th
Will someone who knows PHP update this script and repost it so it works!
( )Robbie May 22nd
Hey All,
I was struggling with this for a long time, but I FINALLY got it working thanks to a compilation of your comments:
1. Move poll folder to root directory
2. Make txt files in data folder blank
3. If not already included, add %> to the end of the poll.php file
4. Replace:
$id = $_GET['vote'] || $_POST['vote'];
With:
$id = isset($_GET['vote']) ? $_GET['vote'] : $_POST['vote'];
and replace:
$id = $_GET['poll'] || $_POST['poll'];
With:
$id = isset($_GET['poll']) ? $_GET['poll'] : $_POST['poll'];
5. To test if poll is working:
- delete text in ips.txt from data folder (system should create txt files)
- script should create votes.txt file once you place a vote for the first time
- delete cookies in your browser, pick another answer this time, etc.
6. For accurate percentiles, change $percent…from poll.php
$percent = round(number_format((($row['votes_count'] / $totalVotes) * 100), 2), 1);
That should do the trick…hope that helps as it bothered me for quite some time!
( )trkl July 3rd
super perferct thank u very much
( )Robbie May 22nd
One thing though, I get an error when trying to vote when js is disabled. The error is Warning: Division by zero in /home2/equalize/public_html/poll/poll.php on line 139
Does anybody know how to fix this so that it will still show results when js is disabled? I’m not sure if this is due to the fact that some options have no votes as yet.
Thanks in advance
( )DevNull July 9th
Try setting the default votes in your db file to 1 for each option
( )Scooter System May 23rd
Adapted with mysql database and a back-office with multiple polls ! Not a small job… 1 day of full work.
Can see an exemple of the results on http://www.scooter-system.fr/catalog/casque-moto.html !
( )John September 16th
Can u share ur work?, i tried to do myself with no exit
.
( )faaliyet October 19th
Hi man ,
( )Do you want to share your perfect solution ?
Thanks a lot.
Robbie May 25th
Figured out why the php didn’t work when disabled, had to do with the sixth step:
$percent = round(number_format((($row['votes_count'] / $totalVotes) * 100), 2), 1);
Revert back to original instead of this and it will work fine:
$percent = round(($row[OPT_VOTES]/$total_votes)*100);
( )Robbie May 25th
Can anybody please tell me how to have this poll incorporated on a page using the php include statement?
Now that I have the poll working fully, I just need it to be called into a div container that will hold php pages.
Any suggestions and assistance would be greatly appreciated!
( )saurabh shah May 25th
wow ! nice one .. i was just looking our something handy and easy one .. this is gng to help me a lot .. thanks a lot for sharing ..
( )kilinkis May 26th
i tried several things of commented above n still cant get it to work
( )Heohni May 28th
What’s your problem? Maybe I can help? I was just setting up the poll successfully today!
( )Tomas May 28th
Also not working here… tried al the steps..
Can see the poll.. I vote… Poll is gone..
I can not see a error message.. so i don’t know what it is…
Tomas May 28th
Problem fixed!!!
In my hosting config i have to options for php..
PHP4 and PHP5… (it was on PHP4)
So, i tried PHP5… And it works!!
Succes!!
Heohni May 28th
Hi! I love jquery! I can make now so many really cool things! I just found your poll today and it took my a little while to figure all out – thanks to Robbie!! – and I got it working! I love this Script! Thanks!!!
( )Design freak May 28th
wow, a very very important and commonly used tool…….. thanks a ton
( )aramtch June 1st
Love this poll… but it acts up when installed on sites that also use mootools. I’ve integrated jquery.noconflict by adding the necessary
var $j = jQuery.noConflict(); code. And I’ve changed all the $ in poll.js to $j
It’s not throwing any js errors, so I think I’ve got poll.js configured correctly.
So now it displays the poll correctly, let’s me vote, and looks like its TRYING to pull the results. But a) my vote doesn’t register in the votes.txt file and b) it shows about 20 rows of NaN% as the results.
Maybe the problem lies in poll.php?
Last note: if I comment out mootools – poll works perfectly fine
Thx in advance for any guidance.
( )wpdigger June 3rd
This is really goo., thanks
( )Andreas June 6th
It works really good. See it in action at http://www.freelanceoverviews.com
( )Carlos August 16th
Can you tell us what you did to fix it?
( )Muhammad Hussain June 7th
Hello jQuery is the best way of using Ajax and JavaScript as i know and this is the coolest example
( )Thanks to giving us this grate stuff.
Regards,
Muhammad Hussain
Robbie June 9th
Does anybody know if this can be used on a php page instead of an html page? I’m using php include statements to bring in a sidebar menu and one of the items I’d like in the sidebar is this poll. I can get the initial poll question showing in the sidebar but I can’t get the results to show in that same sidebar. Can anybody please explain/tell me how I can do this?
( )Thanks in advance.
John June 11th
Hey all,
My version of php is 4.3.10-18. Is it the reason why it’s not working? I made all the changes that Robbie was talking about on May 22nd
( ).
Herry June 15th
Does’t work even demo!
( )hector June 17th
muy bueno, esto es justo lo andaba buscando. saludos.
( )Sumit June 29th
i followed what shannon said above and it works fine for me….just don’t forget to delete your u’r ip address from the ip.txt file everytime u test it….
( )Del33t June 29th
Got it all to work, except one issue. When I submit a vote, it goes to the next “page” and fades in with the result. Yes, result. It only shows my first option in the poll, always showing it at 100%. How am I able to show all 4 :S
( )Kris July 2nd
For those that are still trying to get their votes to register, I have now after a few head scratching hours got it working.
( )Pretty much as everyone has been saying, you need to make the changes above and as Robbie said, you need to delete the txt files (not the text in the files, but the files themselves) and allow the code to generate the files – poll should work after this. To check, just comment out the cookie check in the js file and delete your ip entry in ips.txt.
Not really adding anything new, but hope it helps
Ekrem Birol July 6th
very nice, but even it works.
( )gxideal July 9th
l like it
( )nice July 10th
very good!
thanks
( )Michal July 25th
It depends on version of PHP.
))
( )With 5.3 is everything ok
Adam Smith August 3rd
has anyone actually managed to get this to work?. I am running PHP 5.2.6 on a Windows box. I am experiencing all of the problems mentioned above – even though I made the changes suggested by previous posters.
I dont want to seem ungrateful but it is rather annoying that what appears to be incomplete/untested code, was posted here as a tutorial/example. So far, I have spent the entire afternoon on this, without getting anywhere.
( )dr.emi August 4th
hehehehe…. it’s great code ! I like, thanks net tuts. The other way to create interactive poll.
( )Michael August 4th
I am definitely on board with your article what a neat way to develop a poll. I will definitely be reading more of your articles!!!
( )Niki August 11th
HI, This is verry nice script, but i have one problem. When i vote, i view fade out… and nothing else… the poll result, are missing :s
( )Daniel August 12th
I still cant get it working. Any help?
( )Lise August 12th
I am also getting nothing after fade out despite making all the changes above. I have a question out to my web host about PHP version. Has anyone else identified any other issues that need fixing? And are there any changes we can make to the PHP to make it run on PHP4?
( )Lise August 12th
It turns out I am running PHP 5.2 so the version is not my issue
( )Jordan August 22nd
I guess the versions are not the issues..
( )I tried with different versions, the results still fade away..
Please, help..
Plugo.cz August 24th
Wonderfull, thanks for this tutorial.
( )Martin August 26th
After editing the 2 lines in the poll.php file, remember:
1) Delete the cookie vote_id
2) Delete your IP in ips.txt
I’ve tested it in localhost (xampp) and it’s works fine.
( )Jesse Smith August 26th
I’m having the most common problem – ips.txt does update, but votes.txt does not update.
I have made all the suggested changes. And I have php version 5.2.9
Can someone with a working version send me their poll.php source?
Thanks a lot. jessesmth23@gmail.com
( )Peter Yee August 27th
Tried Robbie’s fix. Still not working.
Same problem with Jesse Smith. ips.txt update, but votes.txt not. my php is 5.2.6
HEELLPP!!! please…..
( )Colton August 28th
Finally working, MAKE SURE that you delete your ip from the ips.txt at first I was just clearing my cookies in my browser and not paying attention to that. Make sure you have ?> at the end of the poll.php document and change the necessary lines in poll.php as stated above.
( )Jody September 6th
Hello,
I would like to show the number of votes for each answer, not only the percentage. It is possible ? if yes how? thanks
( )Lorne Pike September 7th
I tried all of the above changes but still had the problem with it fading out rather than displaying any results. I then removed the ?> at the end, that had been suggested in some of the comments, but kept the changes that shannon mentions above, and voila! For me it’s working fine.
Thanks shannon and everyone!
( )Eldian September 9th
Following Robbie’s instruction above I got this to work on PHP v5.2.5 but has not work on PHP v5.2.10 for me.
For PHP v5.2.10 it will not show the results. After submitting your vote it will simply fade away and then show a blank screen.
If anyone has gotten this to work on PHP v5.2.10 please post your source code.
( )John September 16th
Anyone adapted this great poll for store data in a mysql database?
( )saulius October 3rd
try to double click vote in demo
you should unbind click event from the button after doing preventDefault().
( )jp October 6th
I just installed the script to my local host. everything is working fine. but the result is not visible. noting is visible in he output. its blank.
( )me123 October 8th
Anyone know how I could use this poll with Blogger? thx
( )David Moreen October 23rd
This looks like a really nice poll, I mean it. The problem that I would have is that you are using javascript to determine wether the user has voted yet…
( )faaliyet October 30th
Hi
I’ve rewrited the script to work with mysql. Works perfect without one problem. The problem is cookies of firefox. When I create a new poll, that’s returning with the same cookie. I can’t rate the different poll in FF. That is OK in IE. I think, I should use with sessions and without jquery cookie plugin.
Do you have any idea ?
Thanks.
( )faaliyet
Mark November 3rd
Hi faaliyet,
Do you have the code for the MySQL conversion? I was trying it myself, but i got stuck.
Greetings,
Mark
( )