Live Poll System in PHP Mysql using Ajax

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi friends we have prepared one new interesting tutorial in which we have make one online live Perl system by using PHP script MySQL database and Ajax in short we can also call voting system or polling system which has been made by PHP with Ajax poll system or voting system means user can select one option which he has liked from list of available option or send vote and based on vote we can see result on web page in many social media site where user has published poll and we have take participate in survey and we can see online result this number of person like particular poll option so this type of system we have make here for this we have used PHP script with Ajax and for display poll result we have used bootstrap progress bar on which we can see result now let's start learning this topic so this is our testing database and in this we have one pole table with two columns like Poland and PHP framework here we will make static one pole for user in which we will ask user to which is best PHP framework for year 2018 so when user has submit their poll then that poll data has been stored under this table and based on this data we will display poll result on bootstrap progress bar this is our index page and under this page we have already included query and bootstrap library link under this page first we have make HTML form with method is equal to post and it is equal to pole form under this form we have right static poll question like which is best PHP framework in 2008 here we can also make dynamic pole system also but that tutorial will be take very long time so here we have simple discus pole concept here for display pole option we have used radio input type so here we have write input type is equal to radio name and class is equal to pole option and value is equal to level this code will display laravel option with radio box selection for second option we have right input type is equal to radio name and class is equal to pole option and value is equal to code igniter the third option we have right input type is equal to radio name and class attribute is equal to poll option and value is equal to cakephp for fourth option we have right input type is equal to radio name and class attribute is equal to poll option and value is equal to symphony for display last option we have right input type is equal to radio name and class is equal to poll option and value is equal to Falcon so this way we can display poll option on webpage now we want to submit poll data so we have write input type is equal to submit name and it is equal to poll button by click on this button we can submit poll data below this here we want to display live poll result so here we have write division tag with it is equal to poll result under this tag we will display a result now we have moved to write query code for fetch poll data from server and display on webpage so here we have make fetch poll data function this function will fetch poll data from my SQL table and display on web page in bootstrap progress bar under this function we have start write Ajax request and under this we have write first URL options set to fetch poll data dot PHP here we have send request to this URL in second option we have right method here we can define which method we should use for send data to server so here we have used post method in third option we have write success callback function this function has been called if request completed successfully and it will receive data from server under this we have right dollar with division tag you'd pull results with HTML methods and under this method we have right data this code will display pull data on webpage now we have moved to write PHP code so here we have write dollar Connect variable is equal to new pro class with three argument in first argument we have write MySQL host set to local host database name is equal to testing in second argument username set to root and in third argument password set to blank this way we have make database connection in database connection dot PHP file now we have go to fetch pol data dot PHP file and here we have write include statement and under this we have write database connection dot PHP file this code will make database connection on this page below this we have write dollar PHP framework variable is equal to laravel CodeIgniter kick PHP Phalcon and symphony in array format now we have write dollar total paul row variable is equal to get total rows function with dollar connect variable argument this function will return total rows from pol table so here we have make function get total rows function with dollar connect variable under this we have right dollar query variable is equal to select staff from pole table after this we have a right dollar statement variable is equal to dollar connect variable with preparer statement and under this we have right dollar query variable this will make query for execution now we want to execute query so we have write dollar statement variable with execute method this method will execute query lastly under this function we have write returns statement with dollar statement variable with row count method this method will return total row of query result which an output of this function after getting Pohl table total row now we have write for each loop with dollar PHP framework as dollar row variable under this loop we have write dollar query variable is equal to select staff from pole table where PHP framework column is equal to dollar row variable this query will fetch pole data whose PHP framework column value is equal to dollar o variable below this we have a write dollar statement variable is equal to dollar connect variable with prepare statement with dollar query variable now we want to execute query so we have right dollar statement variable with execute method this method will execute query after this we have write dollar total row variable is equal to dollar statement with row count method this method will return total row from query execution now we want to get percentage vote of particular PHP framework from total votes so here we have write dollar percentage vote variable is equal to PHP round function and under this we have write dollar total row variable / dollar total poll row variable in 200 this code will return percentage share of particular PHP framework from total votes here we have used bootstrap progress bar for display poll result on webpage and bootstrap provide different class for display progress bar in different color so we want to set color for different range percentage so here we have write if statement and under condition we have write dollar percentage vote variable value greater than 40 if this condition true then it will execute this block of code under this block we have write dollar progress spa class variable is equal to progress bar success class you after this we have elsif statement and under condition we have right dollar percentage vote variable value greater than 25 and less than 40 if this condition true then it will execute this block of code and here we have right dollar progress spar class is equal to progress bar info class same way here we have write else if statement and under this block we have write dollar percentage vote class variable value is equal to 10 and less than 25 if this condition true then it will execute this block of code and under this block we have write dollar progress bar class is equal to progress bar warning class now we have write else statement so if the buff condition Falls then it will execute else block of code and under this block we have write dollar progress spar variable is equal to progress bar danger class after this we have a write dollar output variable and in this variable we have appendage tml code so here first we have write dollar row variable which will print particular PHP framework name below this we have write division tag with class is equal to progress this is bootstrap progress bar class under this tag we have right division tag with class is equal to progress bar and dollar progress bar class this is dynamic for display progress bar in different color based on value of percentage of votes after this we have write Aria value now attribute is equal to dollar percentage vote variable this will display current value of progress bar now we have write Aria value minimum is equal to zero this is minimum value and Aria value maximum is equal to hundred this is highest range of this progress bar after this we have write style is equal to width set a value of dollar percentage vote variable this will set width of progress bar color this way we have store progress bar data in dollar output variable now we want to send this data to Ajax request so we have write echo statement with dollar output variable now we have go to index page and we have called this fetch poll data function so when page has been loaded into browser then this function will called and it will display poll data on web page so friends here we can see when page has been loaded into browser then we can see poll question with different option and lastly we can see submit button for submit poll on right side we can see poll result but current it display nothing because we have not submit poll so first we want to submit poll data to server for this here on index page we have write dollar with form it pole form with own method and under this we have write submitted and so form has been submitted then this code will execute under this we have right events dot prevent default method this method will stop to submit form data now we have right dollar with radio button class Perl option with each method by using each method we can check property of each tag whose class is pole option under this method we have write if statement and under condition we have write dollar this with prop methods and under this we have write checked so if any radio button has been checked then this block of code will execute under this block we have right pole option variable is equal to dollar this with value method so here we have store checked radio button value under this pole option variable now we have right if statement and under condition we have right pole option variable value is not equal to blank if this condition true then it will execute if block of code under this block we have write dollar with button it purl button with attribute method with disabled argument this code will disabled submit button for prevent double click on submit button after this we have write form data variable is equal to dollar this with serialized method this method will convert form data into URL encode its string now we have start right Ajax request so first we have write URL option set to pole dot PHP so here we have send request to page in second option we have right method set to post so here we have used post method for send data to server in third option we have write data option in this option we can define which data we want send to server so here we have write form data variable lastly we have write success callback function this function has been called if request completed successfully under this function we have write dollar with form it pole form with 0 index with reset method this method will reset form data after this we have write dollar with submit button it purl button with attribute method in which we have set disabled set to false this code will enable submit button below this we have called fetch pole data function this function will fetch latest poll data from database and display on webpage we have rightt alert popup message like polls submitted successfully this message will be pop-up on web page now we have moved to write PHP code on polled off PHP page and here first we have write include statement with database connection dot PHP page it will make database connection below this we have write if statement and under condition we have write is set function with dollar post-poll option variable if this variable value is set then it will execute if block of code under this block we have write dollar query variable is equal to insert into pol table with table column like PHP framework with values get from double colon PHP framework below this we have write dollar data variable is equal to array with key double colon PHP framework with value get from dollar post-poll option variable now we have write dollar statement variable is equal to dollar connect variable with prepare statement with dollar query variable lastly we want to execute query so we have write dollar statement variable with execute method and under this method we have write dollar data variable this method will execute insert query and insert data into pol table so here our code is ready so we have saved this code in check output in browser friends first we have refresh page and now on left side we can see one pole four which is best PHP framework in 2018 with different option with submit button and on right side we can see live poll result but currently it display nothing now we have select laravel option and click on submit button after click on submit button we have received pearls submitted popup message on webpage and on right side we can see popup result in bootstrap progress bar so here we can see in laravel option we can see hundred percentage Programmer like this framework and here only one person has submit poll and he has select laravel option so it is display hundred percentage in laravel now we have again select CodeIgniter option and click on submit button after click on submit button live poll results has been changed and not it display laravel framework 50 percentage and code ignites a framework 50 percentage because here two person has submit poll in which one person has like laravel and other person is like codeigniter framework so in both framework we can see 50 percentage and other framework display nothing so this way pole system has work this system has been used forget opinion public on particular topic then this type of system can be used this system can use for voting purpose also and it has display live result on webpage currently on many social media website we see poll has been published by user for take survey on any topic so this way we can make simple online poll or voting system by using PHP script MySQL database with Ajax so it can display result on page without refresh of web page if you have any query regarding this video tutorial part please comment your query in comment box and if you liked this video tutorial please share with your friends or even you can also share on social media also if you want to get more update regarding our video tutorial please subscribe our youtube channel forget more update regarding release of future video lastly keep watching our youtube channel thanks for watching this video tutorial
Info
Channel: Webslesson
Views: 27,196
Rating: undefined out of 5
Keywords: ajax poll, poll script, php poll script mysql, live voting system using php ajax, polling system in php, php voting script, poll system ajax, vote php, voting system with ajax, online voting system project in php, php live voting, ajax poll script with php mysql & jquery, how to create online voting system in php, php ajax poll, php and ajax
Id: 57Y9qOj47A4
Channel Id: undefined
Length: 21min 47sec (1307 seconds)
Published: Wed May 02 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.