Ajax Poll Script With PHP, MySQL & jQuery
In this tutorial, we'll be creating an Ajax Poll Script that displays the results with colored and animated lines using PHP, MySQL and jQuery.
The script has a pretty easy logic and can be implemented into any website quickly by simply calling a php function like getPoll(2) which brings the second poll.
The code has 3 parts: HTML, JavaScript (jQuery) and PHP. Let's start with the easiest one:
HTML
The HTML for the poll is generated within the PHP function which is usually nice as it is only a 1-line-code and doesn't create a visual pollution in the overall HTML.
<div id="pollWrap"> <form action="inc/functions.php?action=vote" method="post" name="pollForm"> <h3>Poll Question 1</h3> <ul> <li><input id="pollRadioButton1" name="pollAnswerID" type="radio" value="1" /> Answer1 for Poll1</li> <li class="pollChart pollChart1"> </li> <li><input id="pollRadioButton2" name="pollAnswerID" type="radio" value="2" /> Answer2 for Poll1</li> <li class="pollChart pollChart2"> </li> </ul> <input id="pollSubmit" name="pollSubmit" type="submit" value="Vote" /> <img alt="Ajax Loader" id="pollAjaxLoader" src="ajaxLoader.gif" /></form> </div>
There is nothing original here. In one of the list items, we mention the answer and provide a unique ID for it which matches that answer's answerID in the database. For the other list item, we reserve it for the colored line, again by giving it the unique ID.
PHP
We first include our db connection file and handle the posted items from the Ajax requests
require("db.php");
//GETTING VARIABLES START
if (isset($_POST['action'])) {
$action = mysql_real_escape_string($_POST['action']);
}
if (isset($_POST['pollAnswerID'])) {
$pollAnswerID = mysql_real_escape_string($_POST['pollAnswerID']);
}
//GETTING VARIABLES END
After that, create the function getPoll which simply loops through the database and creates the HTML for the poll mentioned above.
function getPoll($pollID){
$query = "SELECT * FROM polls LEFT JOIN pollAnswers ON polls.pollID = pollAnswers.pollID WHERE polls.pollID = " . $pollID . " ORDER By pollAnswerListing ASC";
$result = mysql_query($query);
//echo $query;jquery
$pollStartHtml = '';
$pollAnswersHtml = '';
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$pollQuestion = $row['pollQuestion'];
$pollAnswerID = $row['pollAnswerID'];
$pollAnswerValue = $row['pollAnswerValue'];
if ($pollStartHtml == '') {
$pollStartHtml = '<div id="pollWrap"><form name="pollForm" method="post" action="inc/functions.php?action=vote"><h3>' . $pollQuestion .'</h3><ul>';
$pollEndHtml = '</ul><input type="submit" name="pollSubmit" id="pollSubmit" value="Vote" /> <span id="pollMessage"></span><img src="ajaxLoader.gif" alt="Ajax Loader" id="pollAjaxLoader" /></form></div>';
}
$pollAnswersHtml = $pollAnswersHtml . '<li><input name="pollAnswerID" id="pollRadioButton' . $pollAnswerID . '" type="radio" value="' . $pollAnswerID . '" /> ' . $pollAnswerValue .'<span id="pollAnswer' . $pollAnswerID . '"></span></li>';
$pollAnswersHtml = $pollAnswersHtml . '<li class="pollChart pollChart' . $pollAnswerID . '"></li>';
}
echo $pollStartHtml . $pollAnswersHtml . $pollEndHtml;
}
This getPollID function below is for easily getting the ID of the related polls by providing an answerID:
function getPollID($pollAnswerID){
$query = "SELECT pollID FROM pollAnswers WHERE pollAnswerID = ".$pollAnswerID." LIMIT 1";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
return $row['pollID'];
}
And, the getPollResults function which is kinda tricky but not that much.
When ran, it returns a string like: 1|13|#ffcc00-2|32|#00ff00-3|18|#cc0000-63" which the first number is the answerID, second is the points it has and third is the color for that answer's animated line.
The last number is the sum of all points for easily calculating percentages.
The string is parsed in the JavaScript side later on.
function getPollResults($pollID){
$colorArray = array(1 => "#ffcc00", "#00ff00", "#cc0000", "#0066cc", "#ff0099", "#ffcc00", "#00ff00", "#cc0000", "#0066cc", "#ff0099");
$colorCounter = 1;
$query = "SELECT pollAnswerID, pollAnswerPoints FROM pollAnswers WHERE pollID = ".$pollID."";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
if ($pollResults == "") {
$pollResults = $row['pollAnswerID'] . "|" . $row['pollAnswerPoints'] . "|" . $colorArray[$colorCounter];
} else {
$pollResults = $pollResults . "-" . $row['pollAnswerID'] . "|" . $row['pollAnswerPoints'] . "|" . $colorArray[$colorCounter];
}
$colorCounter = $colorCounter + 1;
}
$query = "SELECT SUM(pollAnswerPoints) FROM pollAnswers WHERE pollID = ".$pollID."";
$result = mysql_query($query);
$row = mysql_fetch_array( $result );
$pollResults = $pollResults . "-" . $row['SUM(pollAnswerPoints)'];
echo $pollResults;
}
The last PHP code is the voting part which also sets a cookie:
//VOTE START
if ($action == "vote"){
if (isset($_COOKIE["poll" . getPollID($pollAnswerID)])) {
echo "voted";
} else {
$query = "UPDATE pollAnswers SET pollAnswerPoints = pollAnswerPoints + 1 WHERE pollAnswerID = ".$pollAnswerID."";
mysql_query($query) or die('Error, insert query failed');
setcookie("poll" . getPollID($pollAnswerID), 1, time()+259200, "/", ".webresourcesdepot.com");
getPollResults(1);
}
}
//VOTE END
if (mysql_real_escape_string($_GET['cleanCookie']) == 1){
setcookie("poll1", "", time()-3600, "/", ".webresourcesdepot.com");
header('Location: http://webresourcesdepot.com/wp-content/uploads/file/ajax-poll-script/');
}
jQuery (JavaScript)
It is only an Ajax request that posts the selected answer to the PHP code, gets the string in return, parses it and makes some show/hide tricks for displaying and hiding the messages or loaders.
Here it is:
$(document).ready(function() {
$("#pollAjaxLoader").hide(); //hide the ajax loader
$("#pollMessage").hide(); //hide the ajax loader
$("#pollSubmit").click(function() {
var pollAnswerVal = $('input:radio[name=pollAnswerID]:checked').val();//Getting the value of a selected radio element.
if ($('input:radio[name=pollAnswerID]:checked').length) {
$("#pollAjaxLoader").show(); //show the ajax loader
$.ajax({
type: "POST",
url: "inc/functions.php",
data: { pollAnswerID: pollAnswerVal, action: "vote" },
success: function(theResponse) {
//the functions.php returns a response like "1|13|#ffcc00-2|32|#00ff00-3|18|#cc0000-63" which the first number is the answerID, second is the points it has and third is the color for that answer's graph. The last number is the sum of all points for easilt calculating percentages.
if (theResponse == "voted") {
$("#pollAjaxLoader").hide(); //hide the ajax loader
$("#pollMessage").html("sorry, you already voted.").fadeTo("slow", 1);
} else {
var numberOfAnswers = (theResponse).split("-").length-2;//calculate the number of answers
var splittedResponse = (theResponse).split("-");
var pollAnswerTotalPoints = splittedResponse[numberOfAnswers+1];
for (i=0;i<=numberOfAnswers;i++)
{
var splittedAnswer = (splittedResponse[i]).split("|");
var pollAnswerID = (splittedAnswer[0]);
var pollAnswerPoints = (splittedAnswer[1]);
var pollAnswerColor = (splittedAnswer[2]);
var pollPercentage = (100 * pollAnswerPoints / pollAnswerTotalPoints);
$(".pollChart" + pollAnswerID).css("background-color",pollAnswerColor);
$(".pollChart" + pollAnswerID).animate({width:pollPercentage + "%"});
$("#pollAnswer" + pollAnswerID).html(" (" + Math.round(pollPercentage) + "% - " + pollAnswerPoints + " votes)");
$("#pollRadioButton" + pollAnswerID).attr("disabled", "disabled"); //disable the radio buttons
}
$("#pollAjaxLoader").hide(); //hide the ajax loader again
$("#pollSubmit").attr("disabled", "disabled"); //disable the submit button
}
}
});
return false;
} else {
$("#pollMessage").html("please select an answer.").fadeTo("slow", 1, function(){
setTimeout(function() {
$("#pollMessage").fadeOut("slow");
}, 3000);
});
return false;
}
});
});
The JavaScript code is well-commented and is pretty self-explanatory. Don't let the number of lines afraid you, most of them are just the make-up.
That's all.
Download: http://www.webresourcesdepot.com/?download=AjaxPollS...
- Tags:
Mysql Php
- Filed under: Extras, Goodies, Licenses, Other License, Polls & Surveys, Tutorials
- 96 Comments













96 Responses for "Ajax Poll Script With PHP, MySQL & jQuery"
I like it!
Thanks!
Does nobody still not code in mysqli or pdo these days
Great share, thank you!
Very cute!
Great! Thanks
Nice work. Thank you for sharing
Can you show me a method to clear the cookie in my development version of this tutorial. I tried using a submit button to run a PHP page with the following line, but it did not work.
setcookie(“poll” . getPollID($pollAnswerID), 1, time() -259210, “/”);
Thanks!
WBR
@William,
Your code looks ok and I think it fails in the “/” part.
Suggest you use the domain while setting the cookie at the voting process like:
setcookie(“poll” . getPollID($pollAnswerID), 1, time()+259200, “/”, “.domain.com”);
setcookie(“poll” . getPollID($pollAnswerID), 1, time()-259200, “/”, “.domain.com”);
To make sure, you can check the cookie in your browsers “view cookies” part and verify if there is a mismatch.
The javascript part is not working correctly. Is there something wrong?
@Maek,
Whn I check it with Firebug, the eror below is generated in your eample:
***
Cannot modify header information – headers already sent by
***
which is generally a whitespace problem.
Can you make sure that there is no whitespace in the functions.php and db.php files.
More about the error: http://www.geeklog.net/faqman/index.php?op=view&t=38
hi there, When i install, it comes up with this error, can someone tell me what im doing wrong. I checked everything, and i followed the install instructions.
Heres the error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/scenepr1/public_html/domains/inspiredagency.com/poll/inc/functions.php on line 14
thanks
Whether it can be set to a visitor can vote every 24 hours after?
and if you can stand next to the button and see the vote result. If all this can then be extra poll
tnx
Can this code be modified to make a poll with more than one question? Also, can you do open-ended questions and multiple choice questions? That is one thing I cannot find on the web — an equivilent to the excellent Adobe Connect Polling feature…
Hy. How i make if i vote once, next time i refresh the page to show the vote results only? Thx
to Dominic and everyone who has mysql “warning..line14″
that error came from your MySQL
99% that you have pollanswers instead of pollAnswers (note capitalized letter A).. or you can properly rename sql queries in your php (if you don’t have direct access t your db).
Anyways, I’m suggesting to rename that table to pollAnswers and everything will work like a charm.
How to get the results of the poll even if you have not voted?
@Kamil,
Thanks for the info on that.
@Jean,
The feature is not included by default but you can easily extend the code for that.
First at all apologise my poor english. Im from Argentina.
Testing the poll i have one error. I have to make a poll with 4 categories, so created on DB table pull the 4 categories with diferent pollQuestion autoincremente pollID and pollStatus 1 for all. The problem appears when on index.php i put this:
The first question or categorie work ok but the others 2 showme the loader and when i click on vote send me to
http://localhost/………./ajax-poll/inc/functions.php?action=vote
and didnt showme any results.
Excuse me again, and TKS a lot!!!
index.php i put this:
either with 2,3 or 4, example:
but works ok like this:
TKS!!
Notice: Undefined index: action in G:\wamp\www4\polls\functions.php on line 5
Notice: Undefined index: pollAnswerID in G:\wamp\www4\polls\functions.php on line 6
and
Notice: Undefined variable: pollStartphp in G:\wamp\www4\polls\functions.php on line 21
Notice: Undefined variable: pollAnswersHtml in G:\wamp\www4\polls\functions.php on line 25
Notice: Undefined variable: pollStartphp in G:\wamp\www4\polls\functions.php on line
Hi and thanks for the poll!
I got it working after changing pollAnswers to pollanswers, but now I would like to have multiple polls on 1 page. When I do this though, all polls stop working, and ajaxloader.gif is visible on the second poll.
Is there an easy way to fix this?
Thanks!
i just can say
great job!
@kamil,
thx, but still getting the error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line 14
what permissions should i have on the server files?
i changed all capital A to lowercase a – in the actual files, and left the mysql stuff alone.
any thing else i could be missing?
thx – r
Hy. How i make if i vote once, next time i refresh the page to show the vote results only? Thx
Hy. How i make if i vote once, next time i refresh the page to show the vote results only? Thx
@Taner,
I suggest implementing a cookie or IP-based control mechanism.
hey this scripts works greatly.but i need to see the result even if i havenot voted can u help me please
Is there a way to integrate this into a WordPress post? I’ve got it working in the sidebar, but I can’t call the function in a post.
Thanks in advance
I love this button: ” clear the cookie to vote again”
i got this errors when run it any body can resolve it
i work in xamp
Notice: Undefined index: action in C:\xampp\htdocs\xx\ajax-poll\inc\functions.php on line 4
Notice: Undefined index: pollAnswerID in C:\xampp\htdocs\xx\ajax-poll\inc\functions.php on line 5
Notice: Undefined variable: pollStartHtml in C:\xampp\htdocs\xx\ajax-poll\inc\functions.php on line 20
Notice: Undefined variable: pollAnswersHtml in C:\xampp\htdocs\xx\ajax-poll\inc\functions.php on line 24
i want to create link to ‘View Results’ beside Vote button. what would be the url for View Results ? Can anyone help? I need that badly
@sujan,
That’s very easy but I hope you are a little familiar with JS and PHP.
Just add this at the end of inc/functions.php:
if ($action == “getResults”){
getPollResults(1);
}
}
Insert the JS below to the js/poll.js just before the last “});”:
$(“.showResults”).click(function() {
$(“#pollAjaxLoader”).show(); //show the ajax loader
$.ajax({
type: “POST”,
url: “inc/functions.php”,
data: { pollAnswerID: pollAnswerVal, action: “getResults” },
success: function(theResponse) {
var numberOfAnswers = (theResponse).split(“-”).length-2;//calculate the number of answers
var splittedResponse = (theResponse).split(“-”);
var pollAnswerTotalPoints = splittedResponse[numberOfAnswers+1];
for (i=0;i<=numberOfAnswers;i++)
{
var splittedAnswer = (splittedResponse[i]).split(“|”);
var pollAnswerID = (splittedAnswer[0]);
var pollAnswerPoints = (splittedAnswer[1]);
var pollAnswerColor = (splittedAnswer[2]);
var pollPercentage = (100 * pollAnswerPoints / pollAnswerTotalPoints);
$(“.pollChart” + pollAnswerID).css(“background-color”,pollAnswerColor);
$(“.pollChart” + pollAnswerID).animate({width:pollPercentage + “%”});
$(“#pollAnswer” + pollAnswerID).html(” (” + Math.round(pollPercentage) + “% – ” + pollAnswerPoints + ” votes)”);
$(“#pollRadioButton” + pollAnswerID).attr(“disabled”, “disabled”); //disable the radio buttons
}
$(“#pollAjaxLoader”).hide(); //hide the ajax loader again
$(“#pollSubmit”).attr(“disabled”, “disabled”); //disable the submit button
}
});
return false;
});
And give the class “showResults” to the HTML element that wraps your “view results” text.
There can be typos in the code I wrote but simply, it only asks for the poll results and parses just the same way it does when someone votes.
This could have been done in a much smarter way without duplicating the code but this is a quick workaround.
Hi, Thx alot for this poll script
i got aproblem ..
when i press on submit button it became “disabled” >> that means that all thing is right .. But no results shown !!
i hope to help in this
@Alaa,
I suggets checking it with Firebug to find out if any errors are generated.
thanks a lot
“And give the class “showResults” to the HTML element that wraps your “view results” text.”
can u give me one more example for this one?
a href=”???????” class=”showResults”>View Results</a
You might also be able to post the database?
Thanks.
@@Delano,
It is included in the download package.
i still could not get result of poll without voting.
how can i show poll result without voting? I tried all above codes but still ….
.
please do help.
thank you !
Hi, I’m getting these error, Do you know, What can be?
Notice: Undefined index: action in C:\wamp\www\concurso\poll\inc\functions.php on line 4
Notice: Undefined index: pollAnswerID in C:\wamp\www\concurso\poll\inc\functions.php on line 5
Notice: Undefined variable: pollStartHtml in C:\wamp\www\concurso\poll\inc\functions.php on line 20
Notice: Undefined variable: pollAnswersHtml in C:\wamp\www\concurso\poll\inc\functions.php on line 24
BR
@Julio,
Updates the download file which should now be working fine (only updated the functions.php file).
Where can I find the SQL tables?
I cant find it ….???
I’ve tried to make my own, but i cant…
@Anders,
Seems like I didn’t add it after the last update. Fixed now.
I think I found a bug. If you press vote really fast it votes several times. Checked it in my website too and the same thing happens. So I changed some code in poll.js .I moved the ” $(“#pollSubmit”).attr(“disabled”, “disabled”);”
to just below $(“#pollSubmit”).click(function()
{ $(“#pollSubmit”).attr(“disabled”, “disabled”);
and now works fine.
Btw can I check someones IP instead of a cookie when he clicks vote. How can I do that in this poll ?
thanks!
Damm didn’t think about not selecting something and pressing click. So i guess the problems persist.
Ok fixed it for good.Now you can only vote once and no mater how fast you press the vote button and if you don’t select anything the button is no longer disabled.The correct code was:
change to the poll.js
I moved the : “$(“#pollSubmit”).attr(“disabled”,“disabled”);”
As seen just below:
if ($(‘input:radio[name=pollAnswerID]:checked’).length) {
$(“#pollSubmit”).attr(“disabled”, “disabled”);
$.ajax({
Now the only problem i have with the poll is is it can vote based on ip and its perfect.
hi dear friend
thank you for nice code.i have suggestion.could you put MySQL part code(like tables)in your download package.i think it would be really useful
Nice poll!
However I get this error:
“Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /customers/vinde.eu/vinde.eu/httpd.www/poll/inc/functions.php on line 22″
Can anyone help me?
Great tutorial and script, thank you for taking the time to put this together. I got this to work easily with pollID1 but I can’t seem to get other pollIDs to return results. I would like to be able to have multiple polls on one page. Is this possible?
The guide is not good for people which cannot html and php. I cannot this install.
nice poll
but i get error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a2353437/public_html/ajax-poll/inc/functions.php on line 22
anyone can help me??
how to set 24 hours cookie. Its mean users can vote each day one poll. Its possible ….?
@bleng,
Yes, definitely. I suggest checking: http://www.w3schools.com/php/php_cookies.asp
i tried this poll on http://poll.comze.com/ . But ihave problem.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a1515724/public_html/inc/functions.php on line 22
how i fix this issue
Thanks for the script. I have a problem. Everything works but not the results. When you vote it wont show the results. (testing on Mozilla v.3.6.25).
@Kevin
“Thanks for the script. I have a problem. Everything works but not the results. When you vote it wont show the results. (testing on Mozilla v.3.6.25).”
1> First : function getPollResults($pollID){
$pollResults = ”;
2> Second: change if ($pollResults == ” “) to if ($pollResults == ”)
So that you’ll fix this
thank you for Ajax Poll Script
unfortunately the results fix didnt work
Getting errors:
Notice: Undefined variable: action in web/content/test/poll/inc/functions.php on line 69
Notice: Undefined index: cleanCookie in /web/content/test/poll/inc/functions.php on line 82
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /web/content/test/poll/inc/functions.php on line 22
Notice: Undefined variable: pollEndHtml in /web/content/test/poll/inc/functions.php on line 35
I got error too..Please help.
Notice: Undefined variable: action in web/content/test/poll/inc/functions.php on line 69
Notice: Undefined index: cleanCookie in /web/content/test/poll/inc/functions.php on line 82
How can you change this to have only two (rather than three) poll options?
@aaron,
The options are stored in the database. You can add any number of options.
The pool works great (thank you btw) when I have just one poll. But It doesn’t seem to work when I create a second poll. I think It might be just mysql stuff when I added a new poll. Does this look right to create another poll with two possible answers:
– Do these two create the two possible answers ?
INSERT INTO `pollAnswers` VALUES (’1′, ’2′, ‘Green Light’, ’1′, ’1′);
INSERT INTO `pollAnswers` VALUES (’2′, ’2′, ‘Cancel’, ’1′, ’1′);
– Does this create the second poll?
INSERT INTO `polls` VALUES (’2′, ‘Poll Question 2′, ’1′);
Can you clarify what pollAnswerValue, pollAnswerPoints, pollAnswerListing
Thanks again for the tutorial
sorry poll (not pool)
Notice: Undefined index: action in C:\wamp\www\ajax-poll\inc\functions.php on line 69
Notice: Undefined index: cleanCookie in C:\wamp\www\ajax-poll\inc\functions.php on line 82
What should I do to fix this? Thanks.
i got error too
Notice: Undefined variable: action in C:\xampp\htdocs\ajax-poll\inc\functions.php on line 69
Notice: Undefined index: cleanCookie in C:\xampp\htdocs\ajax-poll\inc\functions.php on line 82
I am stuck into this..
I am getting error as “uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMWindow.getComputedStyle]” nsresult: “0×80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)” location: “JS frame :: http://localhost:8080/ajax-poll/inc/js/jquery-1.4.2.min.js :: :: line 4″ data: no]
http://localhost:8080/ajax-poll/inc/js/jquery-1.4.2.min.js
Line 2″
Please help me soon…..the options results are shown as NAN% also
Shalin:
try changing db table name from
pollAnswers
to
pollanswers
in your functions.php file. There are several occurrences, remember to change them all.
I also found out that there is a hardcoded poll id in functions.php line 77 so change
getPollResults(1);
to
getPollResults(getPollID($pollAnswerID));
I’m trying to submit the vote as soon as people press the radio button by adding;
onClick=”document.getElementById(‘pollSubmit’).click();”
to the radio button html element in functions.php
but apparently that gives an unexpected T_STRING on line 32 in functions.php which atm consists of:
$pollAnswersHtml = $pollAnswersHtml . ‘ ‘ . $pollAnswerValue .”;
I’ve tried everything within my understanding and its driving me insane :/ any suggestions?
Thanks in advance
Awesome the copy paste failed, no surprise there,
this pic should give a better view; the third line is line 32
http://i.imgur.com/EhW1E.png
Well what dyou know;
onClick=”document.getElementById(\’pollSubmit\’).click();”
that should work;
tho now it opens URL/scripts/poll/inc/functions.php?action=vote as a new page
any ideas?
Thanks in advance
Woot it works ^^
as previously suggested by someone i moved the disabling of the submit button line much higher up, tho for some reason also placed the disabling of the radio buttons over there, and that was not a good idea x]
Having trouble. I installed my database, and i got this error message.
How can i solve this/?
Thanks.
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
Very nice, and funny how close it was to the one I developed just before visiting this website ^^
Although he made the suggestion for a button to display the results, I could not follow your explanation for a comment above. Could assist in the implementation of this button to display the results? Sorry for English. I am Brazilian. Thank you.
Hi,
I’ve installed the files, but I get an error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /public_html/poll/inc/functions.php on line 22
can anybody help?
thanks
some one please update table schema for poll.
Hi. I converted this great script from PHP to Classical ASP. Everything is Ok. The script works well but I want to ask that how can we modify this script for showing the voted poll results. Namely, When someone voted this script then came to site again and want to vote the same poll again but in this version there is only a warning such as “You have voted this poll before.” but with this warning can we load the show results with the standart animate function?
I’m not an expert of Jquery or Php but i try to do something. i need your experience, please give me some advice if possible a working code maybe:))
i have problems trying to add more polls in the same page. anyone knows how to solve this problem, because it doesnt work when you put more polls, the #pollAjaxLoader still show and when i push vote shows a blank page.
anyone knows how to put more polls in the same page and work?. because i tried but it doesnt work. i think i have to change the code but i dont know how, because the forms and input names in the two or three polls are the same so i don’t know how to modified the code. thanks
HI,
I also faced the notice errors but i resolved by declaring the $action=”; and $_GET['cleancookie']=”;
Now when i click on vote,
Following functinality performs well:
1)A session gets created,
2) User is not allowed to vote more than once
3)the selection is entered in the db.
But when you click on vote results are not displayed, it shows loading
Plz help.
poll is perfect but there must be form for adding new question and answer after that we just need to change poll id and i also can’t find the way to change poll question
Problem:
When I press ‘Submit’ button, vote insert nicely in mysql. But the result page not shows. The voting page remain active and a revolving loading gif image shows next to submit button.
After hard work, now its working.
But cookie not setting up. So I can vote unlimited.
Please tell me how to solve this, I mean how cookie will set up and how can I setup cookie for 7 days.
when there is declaration of $pollResults??
Hello
How can I add the fields name and email ? I’ve added it in the php file but I don’t know how to add it in the Ajax file
Thanks a lot
Hi. I just want to say that i use this script locally, its working fine but as i upload it on online server, it display me empty page, means its not getting form from functions.php.
Kindly reply me that how to resolve this issue?
WTF?
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/s/stazarov/autoprofi.com/public_html/newyear2013/poll/ajax-poll/inc/functions.php on line 22
Hi. I just want to say that i use this script locally, its working fine but as i upload it on online server, it display me empty page, means its not getting form from functions.php.
Kindly reply me that how to resolve this issue?
YOU CAN SEE ITS EXAMPLE LIVE.
http://www.pacecircle.com/polls
Hello,
what must i do to fix this:
( ! ) Notice: Undefined variable: action in E:\wamp\www\ajax-poll-script\ajax-poll\inc\functions.php on line 70
Call Stack
# Time Memory Function Location
1 0.0004 673000 {main}( ) ..\index.php:0
2 0.0045 722832 require( ‘E:\wamp\www\ajax-poll-script\ajax-poll\inc\functions.php’ ) ..\index.php:3
( ! ) Notice: Undefined index: cleanCookie in E:\wamp\www\ajax-poll-script\ajax-poll\inc\functions.php on line 83
Call Stack
# Time Memory Function Location
1 0.0004 673000 {main}( ) ..\index.php:0
2 0.0045 722832 require( ‘E:\wamp\www\ajax-poll-script\ajax-poll\inc\functions.php’ ) ..\index.php:3
thaks for your care
is not working. Form not displaying.
http://www.pacecircle.com/polls
For everyone who has mysql “Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/s/stazarov/autoprofi.com/public_html/newyear2013/poll/ajax-poll/inc/functions.php on line 22″, this error came from your connection to MySQL in $dbname. At in db.php change $dbname = “polls”; to $dbname = “your database name”
And, don’t forget to rename the table from “pollanswers” to “pollAnswers” and everything will works fine.
Hi,
While running code after download i am getting this error:-
Notice: Undefined index: cleanCookie in D:\wamp\www\ajax-poll\inc\functions.php on line 82
Notice: Undefined variable: action in D:\wamp\www\ajax-poll\inc\functions.php on line 69
and after select option and click on voter button ajax loader cont.. running and not showing results.
Thanks.
Manish