<?php
	@header('Content-Type: text/html; charset=UTF-8');
	require ('./common.php');
	$db = mysql_connect("{$dbconfig['host']}", "{$dbconfig['user']}", "{$dbconfig['pwd']}"); //连接数据库
	mysql_select_db("{$dbconfig['dbname']}", $db);

	mysql_query("set names utf8");
	$ip = $_SERVER["REMOTE_ADDR"];//获取点赞者ip
	$id = $_POST['id'];

	if(!isset($id) || empty($id)) exit;

	$sql_ip = mysql_query("select love_ip from zzdh_love where love_id = '$id' and love_ip = '$ip'"); //获取点赞记录
	$count = mysql_num_rows($sql_ip); 
	if($count == 0){ //如果没有记录 
   		$sql = "update zzdh_list set love=love+1 where id='$id'"; //更新点赞数量
    	mysql_query( $sql); 
    	$sql_in = "insert into zzdh_love (love_id,love_ip) values ('$id','$ip')"; //记录点赞id以及ip
    	mysql_query( $sql_in); 
    	$result = mysql_query("select love from zzdh_list where id='$id'"); 
    	$row = mysql_fetch_array($result); 
    	$love = $row['love']; //获取点赞数量
   		echo "<span class=\"love-active\"><i class=\"fa fa-heart fa-fw\" aria-hidden=\"true\"></i> $love</span>"; 
	}else{ 
    	echo "<span class=\"love-active\"><i class=\"fa fa-heart fa-fw\" aria-hidden=\"true\"></i> 赞过了</span>"; 
	}
?>