Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Posts
    3

    Unanswered: If an Entry (IP) Exists in the SQL DB, Don't let them Vote

    Hi,

    I'm a MySQL newbie taking on a huge project for myself... and I'm doing pretty well (it's almost done), but there's just one roadblock in my way right now.

    I have a DB of items, and each item has its own built in rating system (good or bad), the rating system works fine, and it records the user's IP address, along with the listing ID they voted on in a seperate table.

    I need the voting script to cross reference the user's IP with that IP table each time they vote, so that if their IP exists for item ID say... 3, then their vote isn't counted.

    For reference, I'll post the rating part of the script I have now... if anyone can help me do that, I'd be really grateful!

    PHP Code:
    <?
    //******************
    // If the Vote is Good
    //******************

    if ($vote == "good") {

    $query "INSERT INTO ip (listingid,ip) VALUES ('$id','$ip')";
    $result mysql_query($query)
       or die (
    "Couldn't Add IP");

    $newrating $row[goodrating] + 1;

    $query "UPDATE host SET goodrating='$newrating' WHERE id='$id'";
    $result mysql_query($query)
       or die (
    "Couldn't Update Good Vote Status</a>");

    ?>

    Thank you. Your praise for this Web 
    Hosting Company has been recorded. 
    You can <a href=listing.php?id=<? echo 
    $id?>>click here</a> to return to <? 
    echo $row[hostname?>.

    <?

    //******************
    // If the Vote is Bad
    //******************

    } elseif ($vote == "bad") {

    $query "INSERT INTO ip (listingid,ip) VALUES ('$id','$ip')";
    $result mysql_query($query)
       or die (
    "Couldn't Add IP");

    $newrating $row[badrating] + 1;

    $query "UPDATE host SET badrating='$newrating' WHERE id='$id'";
    $result mysql_query($query)
       or die (
    "Couldn't Update Bad Vote Status</a>");

    ?>

    Thank you. Your "bad" rating for this 
    Web Hosting Company has been recorded. 
    You can <a href=listing.php?id=<? echo 
    $id?>>click here</a> to return to <? echo 
    $row[hostname?>.

    <?

    //******************
    // If the Vote is Nowhere in Sight
    //******************

    } else {
    echo 
    "No vote specified";
    }
    ?>
    Last edited by mdurrant; 03-22-04 at 19:48.

  2. #2
    Join Date
    Mar 2004
    Posts
    3
    Nevermind,

    It was solved on my own with a simple

    PHP Code:

    $result 
    = @mysql_query("SELECT * FROM ip WHERE listingid=$id AND ip='$ip'");
            while (
    $row =@mysql_fetch_array ($result) )
    {
    if (
    $result) { 
    exit(
    "Can't Vote");
    }


Posting Permissions

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