I've seen a few tutorials online that show you how to create a poll using PHP, but none that did it without a mysql database. This tutorial will try to do just that.
First of all, if you haven't read my Flat File Databases tutorial, or you do not have any prior experience with storing/retrieving information from flat files, go ahead and read that tutorial before you continue.
We're going need a place to work, so go ahead and create a new directory named poll, or whatever you want, so that we can store all of the files necessary for this tutorial in one place.
Ok, now that we've got our directory, let's get started. We need to setup an array that will store the information for our poll(s). This array will need three items. The first item will be the poll question. The second will be another array of the possible options of the poll. The final item will be another array of the votes.
What we're going to have is what is called a multidimensional array. Below is the code for our poll array. Create a new file named 'setup.php' and type or copy/paste the following:
<?php
|
|
Each item in the array of options will correspond to each item in the array of votes. This is how we will calculate how many votes have been made for each option.
Now that we have our array setup, we need to serialize it and stick it into a file, so that we can use is later for adding to our poll data and calculating the poll results. Go ahead and create a new file, I'm going to call mine 'poll.dat'. Stick it in your poll directory that you made earlier.
Add this to your setup.php file then run it:
$dat_file = 'poll.dat';
|
|
After you run setup.php you should see a new file in your poll directory, named 'poll.dat'. If you get errors when you run the script, try CHMODing your poll directory to 777 or 755.
Go on to the next page, where we'll learn how to calculate the results.
| Discuss Tutorial: Flat File Poll | 93 Comments |

Gotta love the way you've set it out, Ron. 


im happy now
it will be on my portfolio is that ok

I just have a small problem...the poll shows up twice!
How do I get it to show up only once? 
