If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > If an Entry (IP) Exists in the SQL DB, Don't let them Vote

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-22-04, 18:45
mdurrant mdurrant is offline
Registered User
 
Join Date: Mar 2004
Posts: 3
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 18:48.
Reply With Quote
  #2 (permalink)  
Old 03-22-04, 20:47
mdurrant mdurrant is offline
Registered User
 
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");
}

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On