Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    voting site. how to keep each user from voting more than once

    hey guys i am fairly new to php and need some advice. i have created a login page for a voting site that allows usernames to vote on positions. i have been informed that i need to track who voted on what and allow each user to only vote once. any ideas on how to do this would be great. i have two tables one for users which has id, username, and password. the other that has the voting positions in it. thanks in advance. richard

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    I actually run a site like this, professionally (bitballot.com but don't mind the home page, I'm running some updates over the next week or two)... to do it, and to do it well, requires a number of tables and a bit of intricacy, specially to do effectively.

    You need a table for users, ballots, questions, options, votes, and registration, to start. You need to keep track of what options go to each question, what questions go to each ballot, and which users are allowed to vote for each ballot, and if they have or haven't voted.Take no offense as I will abstain from further answers, as you're my competition :-P

    I'll just say that this isn't simple to do well... I've been working on the site for 4 years now.

  • #3
    New Coder
    Join Date
    Jun 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    lol hardly this is a simple site for a teachers union to use once a year for voting. nothing as fancy as what you have kicking. teachers will vote on four positions through radio buttons which is submitted to a database. thats it short and simple.

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Oh, then...

    Uh...

    Will there be multiple ballots, namely simultaneously, or one ballot at a time/per year?

  • #5
    New Coder
    Join Date
    Jun 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    only one balot per user. once a year

  • #6
    New Coder
    Join Date
    Jun 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    here is the php used to process the votes.
    PHP Code:
    <?php
     
    //show all $_POST variables the page is receiving.
     
    echo '<pre>Debugging:'print_r($_POST); echo '</pre>';
     
    reset($_POST); //print_r() moves the array pointer to the last value, this resets it to number one.
     //OR,
     
    var_dump($_POST); 
     
     
    mysql_connect("localhost""un""pw") or die(mysql_error()); 
     
    mysql_select_db("membership") or die(mysql_error()); 
     
     
     
    $president=($_POST['president']);
     
    $vp=($_POST['vp']);
     
    $tr=($_POST['tr']);
     
    $sect=($_POST['sect']);
     
     if (
    $president=='other') {
        
    $president=($_POST['pres_txt']);
    }
     if (
    $vp=='other') {
        
    $vp=($_POST['vp_txt']);
    }
     if (
    $tr=='other') {
        
    $tr=($_POST['tr_txt']);
    }
     if (
    $sect=='other') {
        
    $sect=($_POST['sect_txt']);
    }

     
    mysql_query ("INSERT INTO `data` VALUES ('$president', '$vp', '$tr', '$sect')"); 
     echo 
    $query;
      Print 
    "Your vote has been successfully cast."
     
    ?>

  • #7
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Yup, that'll do it in a simple fix... then you can just count after grouping by each candidate and you can get the results. Of course, that assumes you don't want write-ins. If you do, just a bit of cleanup code (trim, strip_html, etc).

  • #8
    New Coder
    Join Date
    Jun 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how do i add which username voted to the table. the usernames are stored in a different table? foriegn key?

  • #9
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Yah, I'd go with a foreign key referring to the user table.

    Ideally, you'd put a list of candidates and no write-ins (or even if you have write-ins) in a diff table and then store the identifiers in a "voted" table, but for your simpler purposes, that's not really necessary.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •