Making Simple Voting System .. (not so simple for me!)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Making Simple Voting System .. (not so simple for me!)

Post by nickman013 »

Hello,

I just need a quick tip on how to store numbers in a database, but everytime someone submits a forum. It counts up one.

I am creating a voting system and my database outputs all the items in the vote... with a forum so when the person voting clicks the vote button, it will add +1 to the number of votes in the database...

I should be OK after I figure this out... Another quick question I have is.. I want to store all the voters IP address' in a database so they cannot vote more than one time.. I am not sure what to store it in.. like a row for each one or...?

I know you are going to say get a pre-scripted code but I cant becasue It will be easier the way I want to do it.

Thanks Alot!!
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

I created mine using a single row in a database. The row has 3 fields which represent the number of votes for the 3 things to vote for. Each time somebody votes for A then the field A is incremented by 1. If somebody votes B then B is incremented by 1.

If you want to log IPs then I'd create a seperate table which adds the IP on each page load and then does a lookup in that table before any voting is done.

Hope that helps,
timclaason
Forum Commoner
Posts: 77
Joined: Tue Dec 16, 2003 9:06 am
Location: WI

Vote

Post by timclaason »

I assume the vote is a choice between 2 or more things. If so:

Code: Select all

$choice = $_POST['choice'];

//May want to create a method to check to see if choice is a valid choice

$convertChoiceToTableValue = convertChoice($choice);  //Find Fieldname in table
$query = "UPDATE votes SET " . $convertChoiceToTableValue . "=" . $convertChoiceToTableValue+1;
I'd probably use a combination of cookies and SQL insert of IP (GetHostByName($REMOTE_ADDR)) to check to make sure they haven't already voted.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Thanks ALOT !!!!!!!! :D :D :D :D :D :D :D :D
Post Reply