Jump to content

Rating System with ip addresses


visualazza

Recommended Posts

hi,

 

im have many rows in a database with one column called rating.

 

I am trying to think of a way to allow a user to rate a file but not be able to rate that file again, but still be able to rate other files they have not rated yet.

 

Basically i would use the update query to rate the file but how would i go about banning the ip address for that row in the db

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/195798-rating-system-with-ip-addresses/
Share on other sites

You need a second table called "ratings" ... you would set it up something like this:

 

ID (of item being rated)  IP (of person doing the rating)

 

so when they rate something, you store their rating in the main table, but you also add their IP address and the ID of the item they rated to the second table.

 

Then, in your rating script, have it check the second table for the ID number of the item... if it finds the same IP address with the same ID number, tell it to return a negative - as in, you already voted on this.

 

It works :)

ok,

 

i quickly did this but i does not work.

 

$id = $row['id'];

$ip=@$REMOTE_ADDR;

$qry = "SELECT * FROM ratings WHERE id='$id' AND ip='$ip'";

 

$result = mysql_query($qry) or die(mysql_error());

        if($result) {

                if(mysql_num_rows($result) == 1) {

echo("You have already rated");

                }else {

echo("<form action=rate.php method=POST><input type=text value=5 size=1 width=1 name=vote maxlength=1><input type=submit value=Go></form>");

                }

        }

 

in my ratings table i have id (of the file) and ip (of a rated user)

 

this should find out if the current users ip address has been added in the db for that file

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.