Page 1 of 1

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

Posted: Wed Dec 06, 2006 4:02 pm
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!!

Posted: Wed Dec 06, 2006 4:32 pm
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,

Vote

Posted: Thu Dec 07, 2006 9:25 am
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.

Posted: Sun Dec 10, 2006 11:38 am
by nickman013
Thanks ALOT !!!!!!!! :D :D :D :D :D :D :D :D