$ip=$_SERVER['REMOTE_ADDR'];
if($_POST['id']) {
$id=$_POST['id'];
$ip_sql=mysql_query("SELECT ip_add FROM image_IP WHERE img_id_fk='$id' AND ip_add='$ip'");
$count=mysql_num_rows($ip_sql);
if($count==0) {
$sql = "UPDATE images SET love=love+1 WHERE img_id='$id'";
mysql_query( $sql);
$sql_in = "INSERT INTO image_IP (ip_add,img_id_fk) VALUES ('$ip','$id')";
mysql_query( $sql_in);
$result=mysql_query("SELECT love FROM images WHERE img_id='$id'");
$row=mysql_fetch_array($result);
$love=$row['love'];
echo "<span class=\"on_img\" align=\"left\">{$love}</span>";
}
else {
$sql = "UPDATE images SET love=love-1 WHERE img_id='$id'";
mysql_query( $sql);
$sql_in = "INSERT INTO image_IP (ip_add,img_id_fk) VALUES ('$ip','$id')";
mysql_query( $sql_in);
$ip_id = mysql_query("SELECT ip_id FROM `image_IP` WHERE `ip_add` = '$ip' LIMIT 1");
$count2=mysql_num_rows($ip_id);
if($count2 !== 0) {
$delete = mysql_query("DELETE FROM `loverating`.`image_IP` WHERE `image_IP`.`ip_id` = '$count2' LIMIT 1");
mysql_query($delete);
}
$result=mysql_query("SELECT love FROM images WHERE img_id='$id'");
$row=mysql_fetch_array($result);
$love=$row['love'];
echo "<span class=\"on_img\" align=\"left\">{$love}</span>";
}
}
Спасибо.