The first step is to create the table that will store the data. You’ll want to learn to use MySQL, using a tutorial such as my own MySQL for Other Applications.
Our table will include an automatically incremented ID field, a choice field, an IP address field, and a timestamp field. You can create it in a GUI such as CocoaMySQL or by using the mysql command line.
Most likely your system administrator will create the database for you. But if you are running MySQL on your own computer, you’ll need to create the database:
CREATE DATABASE poll;
Again, you’ll most likely be given the username by your system administrator. But if you need to create it yourself, you can use something like:
GRANT INSERT, SELECT ON poll.* TO polltaker@localhost IDENTIFIED BY ".gE!KAUcuSk8"
Finally, you will almost certainly need to create the table yourself. A MySQL table consists of a series of column definitions.
CREATE TABLE imaginaries (
id int(11) unsigned NOT NULL auto_increment PRIMARY KEY,
choice varchar(30) NOT NULL,
clientIP varchar(20) NOT NULL,
timestamp int(11) unsigned NOT NULL
);
All of your tables should have an auto increment ID. It makes things a whole lot easier when you start relating one table to another, and when you give users the option of modifying or deleting entries.
The “chloice” is where we’ll put the actual choice that the user made.
The clientIP and the timestamp columns will record the IP address that the client came from when they made their choice, and the Unix time that they made their choice. This may be useful for analysis of the data later. It may, for example, be used to check for fraud or ballot-stuffing.