{"id":1943,"date":"2016-11-09T19:07:11","date_gmt":"2016-11-09T19:07:11","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=1943"},"modified":"2024-08-21T08:43:47","modified_gmt":"2024-08-21T08:43:47","slug":"online-poll-voting-system-php-mysql","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/","title":{"rendered":"Online Poll and Voting System with PHP and MySQL"},"content":{"rendered":"<p><b>Online polls<\/b> are mainly used to identify the choice of web users. Online survey or polls is mostly used on the web today, and many services are available that provide a built-in poll system. However, you can easily implement the <b>online voting system using PHP<\/b> and MySQL. If you want to create your own poll and voting system, this tutorial will help you to create a simple, clean polling or voting system using PHP.<\/p>\n<p>The poll or voting system lets the user share their opinion on a subject by selecting from several options. The system counts all the votes and displays the overall result in percentage. This poll or voting system is often used in market research, surveys, and websites to collect feedback on various topics and understand what people think about them. In this tutorial, we will show you how to build a <b>simple poll script in PHP<\/b>. The example script uses PHP and MySQL to create a poll system without using any JavaScript or jQuery. Also, this voting script store poll data, poll options, and votes into the database using PHP and MySQL.<\/p>\n<h2>Poll Script Functionality<\/h2>\n<p>Poll and options data is stored in the MySQL database. Poll questions and respective options will be fetched from the database and shown to the user. The user can be able to select an option and submit their vote. Once the vote is submitted, it will be stored in the database with the respective poll option. Also, PHP COOKIE will be used to restrict the user from submitting the vote multiple times. The poll result with the total votes count and votes on each option will be displayed on the result page. The result of the poll&#8217;s options will be shown in a percentage bar.<\/p>\n<p>In the example voting script, the following functionality will be implemented.<\/p>\n<ul>\n<li>Fetch poll subject\/question from the database and display with options.<\/li>\n<li>Allow the user to select an answer and submit vote.<\/li>\n<li>Store the vote count in the database for each option.<\/li>\n<li>Display poll voting results on the webpage.<\/li>\n<\/ul>\n<p>Before getting started to build online poll &#038; voting system with PHP, take a look at the file structure.<\/p>\n<pre class=\"file-struc\">poll_voting_system_with_php<span style=\"color:#794938\">\/<\/span>\r\n\u251c\u2500\u2500 index.php\r\n\u251c\u2500\u2500 results.php\r\n\u251c\u2500\u2500 Poll.class.php\r\n\u2514\u2500\u2500 css<span style=\"color:#794938\">\/<\/span>\r\n    \u2514\u2500\u2500 style.css\r\n<\/pre>\n<h2>Create Database Tables<\/h2>\n<p>We will use 3 tables to store polls, options, and voting count in the database.<\/p>\n<p>The following SQL creates a <code>polls<\/code> table in the MySQL database, it holds poll subject\/question info.<\/p>\n<pre style=\"color: rgb(68, 68, 68);\"><span class=\"hljs-keyword\" style=\"font-weight: 700;\">CREATE<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">TABLE<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`polls`<\/span> (\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`id`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">int<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">11<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span> AUTO_INCREMENT,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`subject`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">text<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`created`<\/span> datetime <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`modified`<\/span> datetime <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`status`<\/span> tinyint(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">COMMENT<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'1=Active | 0=Inactive'<\/span>,\r\n  PRIMARY <span class=\"hljs-keyword\" style=\"font-weight: 700;\">KEY<\/span> (<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`id`<\/span>)\r\n) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">ENGINE<\/span>=<span class=\"hljs-keyword\" style=\"font-weight: 700;\">InnoDB<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">CHARSET<\/span>=utf8 <span class=\"hljs-keyword\" style=\"font-weight: 700;\">COLLATE<\/span>=utf8_unicode_ci;<\/pre>\n<p>The following SQL creates a <code>poll_options<\/code> table in the MySQL database, it holds options\/answers associated with the respective poll.<\/p>\n<pre style=\"color: rgb(68, 68, 68);\"><span class=\"hljs-keyword\" style=\"font-weight: 700;\">CREATE<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">TABLE<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_options`<\/span> (\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`id`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">int<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">11<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span> AUTO_INCREMENT,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_id`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">int<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">11<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`name`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">varchar<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">255<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`created`<\/span> datetime <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`modified`<\/span> datetime <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`status`<\/span> tinyint(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">COMMENT<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'1=Active | 0=Inactive'<\/span>,\r\n  PRIMARY <span class=\"hljs-keyword\" style=\"font-weight: 700;\">KEY<\/span> (<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`id`<\/span>),\r\n  <span class=\"hljs-keyword\" style=\"font-weight: 700;\">KEY<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_id`<\/span> (<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_id`<\/span>),\r\n  <span class=\"hljs-keyword\" style=\"font-weight: 700;\">CONSTRAINT<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_options_ibfk_1`<\/span> FOREIGN <span class=\"hljs-keyword\" style=\"font-weight: 700;\">KEY<\/span> (<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_id`<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">REFERENCES<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`polls`<\/span> (<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`id`<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">ON<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DELETE<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">CASCADE<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">ON<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">UPDATE<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NO<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">ACTION<\/span>\r\n) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">ENGINE<\/span>=<span class=\"hljs-keyword\" style=\"font-weight: 700;\">InnoDB<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">CHARSET<\/span>=utf8 <span class=\"hljs-keyword\" style=\"font-weight: 700;\">COLLATE<\/span>=utf8_unicode_ci;<\/pre>\n<p>The following SQL creates a <code>poll_votes<\/code> table in the MySQL database, it holds the voting count for each poll option.<\/p>\n<pre style=\"color: rgb(68, 68, 68);\"><span class=\"hljs-keyword\" style=\"font-weight: 700;\">CREATE<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">TABLE<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_votes`<\/span> (\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`id`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">int<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">11<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span> AUTO_INCREMENT,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_id`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">int<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">11<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_option_id`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">int<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">11<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`vote_count`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">bigint<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">10<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">0<\/span>,\r\n  PRIMARY <span class=\"hljs-keyword\" style=\"font-weight: 700;\">KEY<\/span> (<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`id`<\/span>),\r\n  <span class=\"hljs-keyword\" style=\"font-weight: 700;\">KEY<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_id`<\/span> (<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_id`<\/span>),\r\n  <span class=\"hljs-keyword\" style=\"font-weight: 700;\">KEY<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_option_id`<\/span> (<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_option_id`<\/span>),\r\n  <span class=\"hljs-keyword\" style=\"font-weight: 700;\">CONSTRAINT<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_votes_ibfk_1`<\/span> FOREIGN <span class=\"hljs-keyword\" style=\"font-weight: 700;\">KEY<\/span> (<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_id`<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">REFERENCES<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`polls`<\/span> (<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`id`<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">ON<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DELETE<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">CASCADE<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">ON<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">UPDATE<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NO<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">ACTION<\/span>,\r\n  <span class=\"hljs-keyword\" style=\"font-weight: 700;\">CONSTRAINT<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_votes_ibfk_2`<\/span> FOREIGN <span class=\"hljs-keyword\" style=\"font-weight: 700;\">KEY<\/span> (<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_option_id`<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">REFERENCES<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_options`<\/span> (<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`id`<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">ON<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DELETE<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">CASCADE<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">ON<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">UPDATE<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NO<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">ACTION<\/span>\r\n) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">ENGINE<\/span>=<span class=\"hljs-keyword\" style=\"font-weight: 700;\">InnoDB<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">CHARSET<\/span>=utf8 <span class=\"hljs-keyword\" style=\"font-weight: 700;\">COLLATE<\/span>=utf8_unicode_ci;<\/pre>\n<p>For the demonstration purpose, insert some test data (poll and respective options) in the database.<\/p>\n<pre style=\"color: rgb(68, 68, 68);\"><span class=\"hljs-keyword\" style=\"font-weight: 700;\">INSERT<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">INTO<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`polls`<\/span> (<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`id`<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`subject`<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`created`<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`modified`<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`status`<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">VALUES<\/span>\r\n(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'What is your Favorite Programming Language?'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 04:13:13'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 04:13:13'<\/span>, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>);<\/pre>\n<pre style=\"color: rgb(68, 68, 68);\"><span class=\"hljs-keyword\" style=\"font-weight: 700;\">INSERT<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">INTO<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_options`<\/span> (<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`id`<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`poll_id`<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`name`<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`created`<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`modified`<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`status`<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">VALUES<\/span>\r\n(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'PHP'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 04:13:13'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 04:13:13'<\/span>, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>),\r\n(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">2<\/span>, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'Python'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 04:13:13'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 04:13:13'<\/span>, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>),\r\n(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">3<\/span>, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'JavaScript'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 04:13:13'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 04:13:13'<\/span>, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>),\r\n(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">4<\/span>, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'Java'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 04:13:13'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 04:13:13'<\/span>, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>),\r\n(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">5<\/span>, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'C and C++'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 19:39:46'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 19:39:46'<\/span>, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>),\r\n(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">6<\/span>, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'Ruby'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 19:39:46'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 19:39:46'<\/span>, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>),\r\n(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">7<\/span>, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'Other'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 19:40:25'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'2024-08-18 19:40:25'<\/span>, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>);<\/pre>\n<h2>Poll Class (Poll.class.php)<\/h2>\n<p>The Poll class handles the database related operations (connect, select, insert, update, and delete) using PHP and MySQL. Specify the database host (<code>$dbHost<\/code>), username (<code>$dbUser<\/code>), password (<code>$dbPwd<\/code>), and name (<code>$dbName<\/code>) as per your database server credentials.<\/p>\n<ul>\n<li><code>__construct()<\/code> &#8211; Connect and select the database.<\/li>\n<li><code>getQuery()<\/code> &#8211; Execute the SQL query and return the respective data. It is a private function used by this class only.<\/li>\n<li><code>getPolls()<\/code> &#8211; Fetch the poll and respective options. Also, it can fetch multiple poll data based on the request.<\/li>\n<li><code>vote()<\/code> &#8211; Insert or update the vote count into the database.<\/li>\n<li><code>getResult()<\/code> &#8211; Get poll results with the voting count of each option.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/><\/span><span style=\"color: #FF8000\">\/* <br \/>&nbsp;*&nbsp;Poll&nbsp;Management&nbsp;Class <br \/>&nbsp;*&nbsp;This&nbsp;class&nbsp;is&nbsp;used&nbsp;to&nbsp;manage&nbsp;online&nbsp;poll&nbsp;&amp;&nbsp;voting&nbsp;system&nbsp;with&nbsp;PHP <br \/>&nbsp;*&nbsp;@author&nbsp;&nbsp;&nbsp;&nbsp;CodexWorld.com <br \/>&nbsp;*&nbsp;@url&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http:\/\/www.codexworld.com <br \/>&nbsp;*&nbsp;@license&nbsp;&nbsp;&nbsp;http:\/\/www.codexworld.com\/license <br \/>&nbsp;*\/ <br \/><\/span><span style=\"color: #007700\">class&nbsp;<\/span><span style=\"color: #0000BB\">Poll<\/span><span style=\"color: #007700\">{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<\/span><span style=\"color: #0000BB\">$dbHost&nbsp;&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'localhost'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<\/span><span style=\"color: #0000BB\">$dbUser&nbsp;&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'root'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<\/span><span style=\"color: #0000BB\">$dbPwd&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'root'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<\/span><span style=\"color: #0000BB\">$dbName&nbsp;&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'codexworld_db'<\/span><span style=\"color: #007700\">; <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<\/span><span style=\"color: #0000BB\">$db&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<\/span><span style=\"color: #0000BB\">$pollTbl&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'polls'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<\/span><span style=\"color: #0000BB\">$optTbl&nbsp;&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'poll_options'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<\/span><span style=\"color: #0000BB\">$voteTbl&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'poll_votes'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">__construct<\/span><span style=\"color: #007700\">(){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">db<\/span><span style=\"color: #007700\">){&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Connect&nbsp;to&nbsp;the&nbsp;database <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$conn&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">mysqli<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">dbHost<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">dbUser<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">dbPwd<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">dbName<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(<\/span><span style=\"color: #0000BB\">$conn<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">connect_error<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(<\/span><span style=\"color: #DD0000\">\"Failed&nbsp;to&nbsp;connect&nbsp;with&nbsp;MySQL:&nbsp;\"&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">$conn<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">connect_error<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">db&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$conn<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/* <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Runs&nbsp;query&nbsp;to&nbsp;the&nbsp;database <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;string&nbsp;SQL <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;string&nbsp;count,&nbsp;single,&nbsp;all <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">private&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">getQuery<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$sql<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">$returnType&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$result&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">db<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">query<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$sql<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch(<\/span><span style=\"color: #0000BB\">$returnType<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;<\/span><span style=\"color: #DD0000\">'count'<\/span><span style=\"color: #007700\">: <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$data&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">num_rows<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;<\/span><span style=\"color: #DD0000\">'single'<\/span><span style=\"color: #007700\">: <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$data&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">fetch_assoc<\/span><span style=\"color: #007700\">(); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default: <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">num_rows&nbsp;<\/span><span style=\"color: #007700\">&gt;&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(<\/span><span style=\"color: #0000BB\">$row&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">fetch_assoc<\/span><span style=\"color: #007700\">()){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/* <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Get&nbsp;polls&nbsp;data <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Returns&nbsp;single&nbsp;or&nbsp;multiple&nbsp;poll&nbsp;data&nbsp;with&nbsp;respective&nbsp;options <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;string&nbsp;single,&nbsp;all <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">public&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">getPolls<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$poll_type&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'single'<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$sql&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"SELECT&nbsp;*&nbsp;FROM&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">pollTbl<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"&nbsp;WHERE&nbsp;status&nbsp;=&nbsp;1&nbsp;ORDER&nbsp;BY&nbsp;id&nbsp;DESC\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$result&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getQuery<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$sql<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$poll_type<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!empty(<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(<\/span><span style=\"color: #0000BB\">$poll_type&nbsp;<\/span><span style=\"color: #007700\">==&nbsp;<\/span><span style=\"color: #DD0000\">'single'<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$sql2&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"SELECT&nbsp;*&nbsp;FROM&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">optTbl<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"&nbsp;WHERE&nbsp;poll_id&nbsp;=&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'id'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">\"&nbsp;AND&nbsp;status&nbsp;=&nbsp;1\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$opts_result&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getQuery<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$sql2<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'options'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">$opts_result<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$i&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach(<\/span><span style=\"color: #0000BB\">$result&nbsp;<\/span><span style=\"color: #007700\">as&nbsp;<\/span><span style=\"color: #0000BB\">$prow<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">'poll'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">$prow<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$sql2&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"SELECT&nbsp;*&nbsp;FROM&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">optTbl<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"&nbsp;WHERE&nbsp;poll_id&nbsp;=&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$prow<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'id'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">\"&nbsp;AND&nbsp;status&nbsp;=&nbsp;1\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$opts_result&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getQuery<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$sql2<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">'options'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">$opts_result<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/* <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Insert&nbsp;voting <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;array&nbsp;of&nbsp;poll&nbsp;option&nbsp;data <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">public&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">vote<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$data&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;array()){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!isset(<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_id'<\/span><span style=\"color: #007700\">])&nbsp;||&nbsp;!isset(<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_option_id'<\/span><span style=\"color: #007700\">])&nbsp;||&nbsp;isset(<\/span><span style=\"color: #0000BB\">$_COOKIE<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_voting_id-'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_id'<\/span><span style=\"color: #007700\">]])){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$sql&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"SELECT&nbsp;*&nbsp;FROM&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">voteTbl<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"&nbsp;WHERE&nbsp;poll_id&nbsp;=&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_id'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">\"&nbsp;AND&nbsp;poll_option_id&nbsp;=&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_option_id'<\/span><span style=\"color: #007700\">]; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$preVote&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getQuery<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$sql<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'count'<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(<\/span><span style=\"color: #0000BB\">$preVote&nbsp;<\/span><span style=\"color: #007700\">&gt;&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$query&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"UPDATE&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">voteTbl<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"&nbsp;SET&nbsp;vote_count&nbsp;=&nbsp;vote_count+1&nbsp;WHERE&nbsp;poll_id&nbsp;=&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_id'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">\"&nbsp;AND&nbsp;poll_option_id&nbsp;=&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_option_id'<\/span><span style=\"color: #007700\">]; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$update&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">db<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">query<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$query<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$query&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"INSERT&nbsp;INTO&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">voteTbl<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"&nbsp;(poll_id,poll_option_id,vote_count)&nbsp;VALUES&nbsp;(\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_id'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">\",&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_option_id'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">\",&nbsp;1)\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$insert&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">db<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">query<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$query<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<\/span><span style=\"color: #0000BB\">true<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/* <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Get&nbsp;poll&nbsp;result <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;poll&nbsp;ID <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">public&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">getResult<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$poll_id<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!empty(<\/span><span style=\"color: #0000BB\">$poll_id<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$sql&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"SELECT&nbsp;p.subject,&nbsp;SUM(v.vote_count)&nbsp;as&nbsp;total_votes&nbsp;FROM&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">voteTbl<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"&nbsp;as&nbsp;v&nbsp;LEFT&nbsp;JOIN&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">pollTbl<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"&nbsp;as&nbsp;p&nbsp;ON&nbsp;p.id&nbsp;=&nbsp;v.poll_id&nbsp;WHERE&nbsp;poll_id&nbsp;=&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$poll_id<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$result&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getQuery<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$sql<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'single'<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!empty(<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'subject'<\/span><span style=\"color: #007700\">]; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'total_votes'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'total_votes'<\/span><span style=\"color: #007700\">]; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$sql2&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"SELECT&nbsp;o.id,&nbsp;o.name,&nbsp;v.vote_count&nbsp;FROM&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">optTbl<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"&nbsp;as&nbsp;o&nbsp;LEFT&nbsp;JOIN&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">voteTbl<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">\"&nbsp;as&nbsp;v&nbsp;ON&nbsp;v.poll_option_id&nbsp;=&nbsp;o.id&nbsp;WHERE&nbsp;o.poll_id&nbsp;=&nbsp;\"<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$poll_id<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$opts_result&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getQuery<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$sql2<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!empty(<\/span><span style=\"color: #0000BB\">$opts_result<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach(<\/span><span style=\"color: #0000BB\">$opts_result&nbsp;<\/span><span style=\"color: #007700\">as&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'options'<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'name'<\/span><span style=\"color: #007700\">]]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'vote_count'<\/span><span style=\"color: #007700\">];&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$data<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>} <br \/> <br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span><\/pre>\n<h2>Poll Question and Answer Options (index.php)<\/h2>\n<p>Initially, the poll subject and respective options are displayed. For selecting an option a radio button is placed with each option label. The user can use the submit button to provide their vote. Also, a link will be provided to view the results of the poll.<\/p>\n<ul>\n<li>Fetch poll and related options from the database using the getPolls() function of the Poll class.<\/li>\n<li>If the voting request is submitted, insert the vote count in the database using the vote() function of the Poll class.<\/li>\n<li>Set an identifier in $_COOKIE to signify the user has voted.<\/li>\n<li>Retrieve existing voting info from COOKIE and checked the selected option if already been voted.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;and&nbsp;initialize&nbsp;Poll&nbsp;class&nbsp; <br \/><\/span><span style=\"color: #007700\">include_once&nbsp;<\/span><span style=\"color: #DD0000\">'Poll.class.php'<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$pollDB&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">Poll<\/span><span style=\"color: #007700\">(); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Get&nbsp;poll&nbsp;and&nbsp;options&nbsp;data <br \/><\/span><span style=\"color: #0000BB\">$poll_data&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$pollDB<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getPolls<\/span><span style=\"color: #007700\">(); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;If&nbsp;vote&nbsp;is&nbsp;submitted <br \/><\/span><span style=\"color: #007700\">if(isset(<\/span><span style=\"color: #0000BB\">$_POST<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'voteSubmit'<\/span><span style=\"color: #007700\">])){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;if(!empty(<\/span><span style=\"color: #0000BB\">$_POST<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_id'<\/span><span style=\"color: #007700\">])&nbsp;&amp;&amp;&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$_POST<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'vote_opt'<\/span><span style=\"color: #007700\">])){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Insert&nbsp;voting&nbsp;data <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$voteData&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;array( <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'poll_id'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$_POST<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_id'<\/span><span style=\"color: #007700\">], <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'poll_option_id'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$_POST<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'vote_opt'<\/span><span style=\"color: #007700\">] <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$voteSubmit&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$pollDB<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">vote<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$voteData<\/span><span style=\"color: #007700\">); <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(<\/span><span style=\"color: #0000BB\">$voteSubmit<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Store&nbsp;in&nbsp;$_COOKIE&nbsp;to&nbsp;signify&nbsp;the&nbsp;user&nbsp;has&nbsp;voted <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">setcookie<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'poll_voting_id-'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$_POST<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_id'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$_POST<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'vote_opt'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">time<\/span><span style=\"color: #007700\">()+<\/span><span style=\"color: #0000BB\">60<\/span><span style=\"color: #007700\">*<\/span><span style=\"color: #0000BB\">60<\/span><span style=\"color: #007700\">*<\/span><span style=\"color: #0000BB\">24<\/span><span style=\"color: #007700\">*<\/span><span style=\"color: #0000BB\">365<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$status&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'success'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$statusMsg&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'Your&nbsp;vote&nbsp;has&nbsp;been&nbsp;recorded&nbsp;successfully.'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$status&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'danger'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$statusMsg&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'Your&nbsp;vote&nbsp;has&nbsp;already&nbsp;been&nbsp;submitted!'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$status&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'danger'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$statusMsg&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'Please&nbsp;select&nbsp;an&nbsp;option&nbsp;to&nbsp;vote.'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>} <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Retrieve&nbsp;existing&nbsp;voting&nbsp;info&nbsp;from&nbsp;COOKIE <br \/><\/span><span style=\"color: #007700\">if(!empty(<\/span><span style=\"color: #0000BB\">$_COOKIE<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_voting_id-'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$poll_data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll'<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">'id'<\/span><span style=\"color: #007700\">]])){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$ck_poll_option&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$_COOKIE<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_voting_id-'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$poll_data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll'<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">'id'<\/span><span style=\"color: #007700\">]]; <br \/>} <br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span>\r\n\r\n<span style=\"color: rgb(95, 94, 78);\"><span class=\"hljs-comment\" style=\"color: rgb(108, 107, 90);\">&lt;!-- Status message --&gt;<\/span>  \r\n<span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$statusMsg<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #DD0000\">'&lt;div&nbsp;class=\"alert&nbsp;alert-'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$status<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">'\"&gt;'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$statusMsg<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">'&lt;\/div&gt;'<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span>\r\n\r\n<span class=\"hljs-comment\" style=\"color: rgb(108, 107, 90);\">&lt;!-- Poll &amp; options --&gt;<\/span>\r\n<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"voting-wrap\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">form<\/span> <span class=\"hljs-attr\">method<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"post\"<\/span> <span class=\"hljs-attr\">action<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"\"<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h3<\/span>&gt;<\/span><span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$poll_data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll'<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">'subject'<\/span><span style=\"color: #007700\">];&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h3<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">ul<\/span>&gt;<\/span>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">foreach(<\/span><span style=\"color: #0000BB\">$poll_data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'options'<\/span><span style=\"color: #007700\">]&nbsp;as&nbsp;<\/span><span style=\"color: #0000BB\">$opt<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;existing&nbsp;voting&nbsp;option <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$opt_select&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!empty(<\/span><span style=\"color: #0000BB\">$ck_poll_option<\/span><span style=\"color: #007700\">)&nbsp;&amp;&amp;&nbsp;<\/span><span style=\"color: #0000BB\">$ck_poll_option&nbsp;<\/span><span style=\"color: #007700\">==&nbsp;<\/span><span style=\"color: #0000BB\">$opt<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'id'<\/span><span style=\"color: #007700\">]){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$opt_select&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'checked'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<\/span><span style=\"color: #DD0000\">'&lt;li&gt;&lt;input&nbsp;type=\"radio\"&nbsp;name=\"vote_opt\"&nbsp;value=\"'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$opt<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'id'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">'\"&nbsp;'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$opt_select<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">'&gt;'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$opt<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'name'<\/span><span style=\"color: #007700\">].<\/span><span style=\"color: #DD0000\">'&lt;\/li&gt;'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">ul<\/span>&gt;<\/span>\r\n\r\n        <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"hidden\"<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"poll_id\"<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"<span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$poll_data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll'<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">'id'<\/span><span style=\"color: #007700\">];&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span>\"<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"submit\"<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"voteSubmit\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"btn btn-success\"<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"Submit Vote\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">form<\/span>&gt;<\/span>\r\n<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">div<\/span>&gt;<\/span>\r\n\r\n<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">a<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"results.php?poll_id=<span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$poll_data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll'<\/span><span style=\"color: #007700\">][<\/span><span style=\"color: #DD0000\">'id'<\/span><span style=\"color: #007700\">];&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span>\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"btn btn-primary\"<\/span>&gt;<\/span>View Results &amp;rarr;<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">a<\/span>&gt;<\/span><\/span>\r\n<\/pre>\n<h2>Poll Voting Results (results.php)<\/h2>\n<p>On this page, the voting result of the selected poll is fetched from the database and shown to the user. The voting count of all options is listed in percentage format with a progress bar UI.<\/p>\n<ul>\n<li>Get voting results from the database using the getResult() method of the Poll class.<\/li>\n<li>List all the options, total vote count, and voting percentage in progress bar UI.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;and&nbsp;initialize&nbsp;Poll&nbsp;class&nbsp; <br \/><\/span><span style=\"color: #007700\">include_once&nbsp;<\/span><span style=\"color: #DD0000\">'Poll.class.php'<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$pollDB&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">Poll<\/span><span style=\"color: #007700\">(); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Get&nbsp;poll&nbsp;result&nbsp;data <br \/><\/span><span style=\"color: #0000BB\">$poll_result&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$pollDB<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getResult<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$_GET<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll_id'<\/span><span style=\"color: #007700\">]); <br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span>\r\n\r\n<span style=\"color: rgb(95, 94, 78);\"><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h3<\/span>&gt;<\/span><span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$poll_result<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'poll'<\/span><span style=\"color: #007700\">];&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h3<\/span>&gt;<\/span>\r\n<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span>Total Votes: <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span><sp<span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$poll_result<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'total_votes'<\/span><span style=\"color: #007700\">];&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span>\r\n<span style=\"color: #0000BB\">&lt;?php <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Generate&nbsp;option&nbsp;bars&nbsp;with&nbsp;votes&nbsp;count <br \/><\/span><span style=\"color: #007700\">if(!empty(<\/span><span style=\"color: #0000BB\">$poll_result<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'options'<\/span><span style=\"color: #007700\">])){&nbsp;<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">=<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;foreach(<\/span><span style=\"color: #0000BB\">$poll_result<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'options'<\/span><span style=\"color: #007700\">]&nbsp;as&nbsp;<\/span><span style=\"color: #0000BB\">$opt<\/span><span style=\"color: #007700\">=&gt;<\/span><span style=\"color: #0000BB\">$vote<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$vote_count&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$vote<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$vote<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$vote_percent&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">round<\/span><span style=\"color: #007700\">((<\/span><span style=\"color: #0000BB\">$vote_count<\/span><span style=\"color: #007700\">\/<\/span><span style=\"color: #0000BB\">$poll_result<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'total_votes'<\/span><span style=\"color: #007700\">])*<\/span><span style=\"color: #0000BB\">100<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$vote_percent&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$vote_percent<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$vote_percent<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">'%'<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">'0%'<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"bar-wrap\"<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h4<\/span>&gt;<\/span><span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$opt<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span> <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">span<\/span>&gt;<\/span>(<span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$vote_count<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span> votes<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">span<\/span>&gt;<\/span>)<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h4<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"progress\"<\/span>&gt;<\/span>\r\n            <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"progress-bar bg-<span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$i<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span>\"<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"width: <span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$vote_percent<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span>;\"<\/span>&gt;<\/span><span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$vote_percent<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">div<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">div<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">div<\/span>&gt;<\/span>\r\n<span style=\"color: #0000BB\">&lt;?php&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;$i<\/span><span style=\"color: #007700\">++;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>}&nbsp; <br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span><\/span>\r\n<\/pre>\n<h2>Conclusion<\/h2>\n<p>Here we&#8217;ve tried to show the web poll system creation process with PHP and MySQL. Hope this online voting tutorial helps to understand online polling system and build your own web poll using PHP and MySQL. Also, you can easily extend this simple <b>PHP poll and voting system<\/b> script as per your requirements.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Online polls are mainly used to identify the choice of web users. Online survey or polls is mostly used on the web today, and many services are available that provide a built-in poll system. However, <\/p>\n","protected":false},"author":1,"featured_media":5715,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[19,14,240,241,386],"class_list":["post-1943","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-mysql","tag-php","tag-poll","tag-vote","tag-voting","cat-4-id","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Online Poll and Voting System with PHP and MySQL - CodexWorld<\/title>\n<meta name=\"description\" content=\"Web Poll and Voting System - Build your own poll script using PHP. Example script to create online poll and voting system with PHP and MySQL. Create your own online survey, poll, and voting system using PHP and MySQL.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Online Poll and Voting System with PHP and MySQL - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"Web Poll and Voting System - Build your own poll script using PHP. Example script to create online poll and voting system with PHP and MySQL. Create your own online survey, poll, and voting system using PHP and MySQL.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/\" \/>\n<meta property=\"og:site_name\" content=\"CodexWorld\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:published_time\" content=\"2016-11-09T19:07:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-21T08:43:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/11\/online-poll-voting-system-with-php-mysql-codexworld.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CodexWorld\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codexworldblog\" \/>\n<meta name=\"twitter:site\" content=\"@codexworldweb\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CodexWorld\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/online-poll-voting-system-php-mysql\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/online-poll-voting-system-php-mysql\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"Online Poll and Voting System with PHP and MySQL\",\"datePublished\":\"2016-11-09T19:07:11+00:00\",\"dateModified\":\"2024-08-21T08:43:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/online-poll-voting-system-php-mysql\\\/\"},\"wordCount\":798,\"commentCount\":13,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/online-poll-voting-system-php-mysql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/11\\\/online-poll-voting-system-with-php-mysql-codexworld.png\",\"keywords\":[\"MySQL\",\"PHP\",\"Poll\",\"Vote\",\"Voting\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/online-poll-voting-system-php-mysql\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/online-poll-voting-system-php-mysql\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/online-poll-voting-system-php-mysql\\\/\",\"name\":\"Online Poll and Voting System with PHP and MySQL - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/online-poll-voting-system-php-mysql\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/online-poll-voting-system-php-mysql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/11\\\/online-poll-voting-system-with-php-mysql-codexworld.png\",\"datePublished\":\"2016-11-09T19:07:11+00:00\",\"dateModified\":\"2024-08-21T08:43:47+00:00\",\"description\":\"Web Poll and Voting System - Build your own poll script using PHP. Example script to create online poll and voting system with PHP and MySQL. Create your own online survey, poll, and voting system using PHP and MySQL.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/online-poll-voting-system-php-mysql\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/online-poll-voting-system-php-mysql\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/online-poll-voting-system-php-mysql\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/11\\\/online-poll-voting-system-with-php-mysql-codexworld.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/11\\\/online-poll-voting-system-with-php-mysql-codexworld.png\",\"width\":1920,\"height\":1080,\"caption\":\"online-poll-voting-system-with-php-mysql-codexworld\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/online-poll-voting-system-php-mysql\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Online Poll and Voting System with PHP and MySQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"name\":\"CodexWorld\",\"description\":\"Web &amp; Mobile App Development Company\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codexworld.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\",\"name\":\"CodexWorld\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"width\":200,\"height\":19,\"caption\":\"CodexWorld\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldweb\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codexworld\",\"https:\\\/\\\/www.youtube.com\\\/codexworld\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\",\"name\":\"CodexWorld\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"caption\":\"CodexWorld\"},\"description\":\"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.\",\"sameAs\":[\"http:\\\/\\\/www.codexworld.com\",\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldblog\"],\"url\":\"https:\\\/\\\/www.codexworld.com\\\/author\\\/nitya192265\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Online Poll and Voting System with PHP and MySQL - CodexWorld","description":"Web Poll and Voting System - Build your own poll script using PHP. Example script to create online poll and voting system with PHP and MySQL. Create your own online survey, poll, and voting system using PHP and MySQL.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/","og_locale":"en_US","og_type":"article","og_title":"Online Poll and Voting System with PHP and MySQL - CodexWorld","og_description":"Web Poll and Voting System - Build your own poll script using PHP. Example script to create online poll and voting system with PHP and MySQL. Create your own online survey, poll, and voting system using PHP and MySQL.","og_url":"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2016-11-09T19:07:11+00:00","article_modified_time":"2024-08-21T08:43:47+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/11\/online-poll-voting-system-with-php-mysql-codexworld.png","type":"image\/png"}],"author":"CodexWorld","twitter_card":"summary_large_image","twitter_creator":"@codexworldblog","twitter_site":"@codexworldweb","twitter_misc":{"Written by":"CodexWorld","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"Online Poll and Voting System with PHP and MySQL","datePublished":"2016-11-09T19:07:11+00:00","dateModified":"2024-08-21T08:43:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/"},"wordCount":798,"commentCount":13,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/11\/online-poll-voting-system-with-php-mysql-codexworld.png","keywords":["MySQL","PHP","Poll","Vote","Voting"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/","url":"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/","name":"Online Poll and Voting System with PHP and MySQL - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/11\/online-poll-voting-system-with-php-mysql-codexworld.png","datePublished":"2016-11-09T19:07:11+00:00","dateModified":"2024-08-21T08:43:47+00:00","description":"Web Poll and Voting System - Build your own poll script using PHP. Example script to create online poll and voting system with PHP and MySQL. Create your own online survey, poll, and voting system using PHP and MySQL.","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/11\/online-poll-voting-system-with-php-mysql-codexworld.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/11\/online-poll-voting-system-with-php-mysql-codexworld.png","width":1920,"height":1080,"caption":"online-poll-voting-system-with-php-mysql-codexworld"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/online-poll-voting-system-php-mysql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"Online Poll and Voting System with PHP and MySQL"}]},{"@type":"WebSite","@id":"https:\/\/www.codexworld.com\/#website","url":"https:\/\/www.codexworld.com\/","name":"CodexWorld","description":"Web &amp; Mobile App Development Company","publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codexworld.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codexworld.com\/#organization","name":"CodexWorld","url":"https:\/\/www.codexworld.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","width":200,"height":19,"caption":"CodexWorld"},"image":{"@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldweb","https:\/\/www.linkedin.com\/company\/codexworld","https:\/\/www.youtube.com\/codexworld"]},{"@type":"Person","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0","name":"CodexWorld","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","caption":"CodexWorld"},"description":"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.","sameAs":["http:\/\/www.codexworld.com","https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldblog"],"url":"https:\/\/www.codexworld.com\/author\/nitya192265\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/11\/online-poll-voting-system-with-php-mysql-codexworld.png","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-vl","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/1943","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/comments?post=1943"}],"version-history":[{"count":11,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/1943\/revisions"}],"predecessor-version":[{"id":5714,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/1943\/revisions\/5714"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/5715"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=1943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=1943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=1943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}