Jump to content

Voting


ClassJr07

Recommended Posts

Hey Guys,

I'd like to create a somewhat of a secure voting system where in a page we have about 5 to 10 pictures but in order to vote for one of the pictures you need to enter a "Voting code" once you type in your vote code you no longer can vote again.

Is there something already out there for this? If not, could someone provide a bit of guidance how to compare their "vote code" with the one in a mysql database, and making it so that number cant be used again.

thank you!

Link to comment
Share on other sites

How will they get the vote code and what would prevent them from getting another vote code?

 

Normally you do this with an email address (verified) and possibly in combination with a cookie and/or their IP address.  Even this doesn't doesn't guarantee that they can't vote with another email address.

Link to comment
Share on other sites

Thanks for the quick reply's, so basically here is how this is going to work..

My organization runs a local pageant, the voting system is going to be used as "people choice" so people who attend the pageant can vote. the "voting codes" are going to be unique numbers printed on each ticket stub, so each ticket holder has a number which on the event date can be used to vote on "peoples choice"  

 

we are planning on having a few laptops or tablets lined up so people can vote during intermission times using their codes.

Link to comment
Share on other sites

Put the codes into a database, once a code is used mark the record as used. I've done something similar where a user whose id was stored in $auth_id could vote only once, though in my example they could vote for up or down and change their vote. Here's the relevant bit of code from the up vote section.

$id=$_POST['id'];
$id = mysqli_real_escape_string($link, $id);
$query="SELECT * FROM master_program_votes WHERE auth_id='".$_SESSION['auth_id']."' AND program_id='$id'";
if ($result=  mysqli_query($link, $query)){
    $master_program_votes= mysqli_fetch_assoc($result);
    //print_r($master_program_votes);
    if ($master_program_votes['auth_id']!=''){//user already voted once
        if ($master_program_votes['down_vote']==1) {
            //$vote_change=2;
            $update_query="UPDATE master_program SET up_votes=up_votes+1, down_votes=down_votes-1 WHERE program_id='$id'";
        }else{
            $no_vote_change=true;//they have already voted
            //$update_query="UPDATE master_program SET up_votes=up_votes+1 WHERE auth_id='".$_SESSION['auth_id']."' AND program_id='$id'";
        }
        $master_program_votes['date']=date('Y-m-d');
        $master_program_votes['up_vote']=1;
        $master_program_votes['down_vote']=0;
        $where = "WHERE auth_id='".$_SESSION['auth_id']."' AND program_id='$id'";
        //print_r($master_program_votes);
        $update_result=  dbRowUpdate('master_program_votes', $master_program_votes, $link, $where);
        }else{
            $master_program_votes['date']=date('Y-m-d');
            $master_program_votes['up_vote']=1;
            $master_program_votes['down_vote']=0;
            $master_program_votes['auth_id']=$_SESSION['auth_id'];
            $master_program_votes['program_id']=$id;
            dbRowInsertTEST('master_program_votes', $master_program_votes, $link);
            $update_query="UPDATE master_program SET up_votes=up_votes+1 WHERE program_id='$id'";
            
    }
    
    }
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.