Tracking Votes and only allowing 1 vote per member

Posted by MikeAdams on Stack Overflow See other posts from Stack Overflow or by MikeAdams
Published on 2011-01-15T02:38:34Z Indexed on 2011/01/15 2:53 UTC
Read the original article Hit count: 158

Filed under:
|
|
|
|

What I'm trying to do is count the votes when someone votes on a "page". I think I lost myself trying to figure out how to track when a member votes or not. I can't seem to get the code to tell when a member has voted.

//Generate code ID
    $useXID = intval($_GET['id']);
    $useXrank = $_GET['rank'];

    //if($useXrank!=null && $useXID!=null) {
        $rankcheck = mysql_query('SELECT member_id,code_id FROM code_votes WHERE member_id="'.$_MEMBERINFO_ID.'" AND WHERE code_id="'.$useXID.'"');
            if(!mysql_fetch_array($rankcheck) && $useXrank=="up"){
                $rankset = mysql_query('SELECT * FROM code_votes WHERE member_id="'.$_MEMBERINFO_ID.'"');
                $ranksetfetch = mysql_fetch_array($rankset);
                $rankit = htmlentities($ranksetfetch['ranking']);
                $rankit+="1";
                mysql_query("INSERT INTO code_votes (member_id,code_id) VALUES ('$_MEMBERINFO_ID','$useXID')") or die(mysql_error());
                mysql_query("UPDATE code SET ranking = '".$rankit."' WHERE ID = '".$useXID."'");
            }
            elseif(!mysql_fetch_array($rankcheck) && $useXrank=="down"){
                $rankset = mysql_query('SELECT * FROM code_votes WHERE member_id="'.$_MEMBERINFO_ID.'"');
                $ranksetfetch = mysql_fetch_array($rankset);
                $rankit = htmlentities($ranksetfetch['ranking']);
                $rankit-="1";
                mysql_query("INSERT INTO code_votes (member_id,code_id) VALUES ('$_MEMBERINFO_ID','$useXID')") or die(mysql_error());
                mysql_query("UPDATE code SET ranking = '".$rankit."' WHERE ID = '".$useXID."'");
            }
            // hide vote links since already voted
            elseif(mysql_fetch_array($rankcheck)){$voted="true";}
    //}

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql