<?php


$id = $_GET['id'];
$gvote = $_GET['vote'];

$votat = "false";
$ipc = $_SERVER['REMOTE_ADDR'];
$msg = "Error!";
include 'config.php';

    $link = mysql_connect($baza['host'], $baza['user'], $baza['pass'])
        or die("Could not connect : " . mysql_error());
    mysql_select_db($baza['nume']) or die("Erorr!, DtaBase Name Incorect!");
$table = $baza['table'];
$r = mysql_query("SELECT * FROM $table  WHERE id = '$id'") or die("Erorr!, DtaBase Name Incorect!");;
$a = mysql_fetch_assoc($r);


$vote1 = $a['votes1'];
$vote2 = $a['votes2'];
$ips = $a['ips'];

$q = mysql_query("SELECT * FROM votes  WHERE id = '$id' AND ip = '$ipc'") or die("Erorr!, DtaBase Name Incorect!");;
$w = mysql_fetch_assoc($q);
if ($w['time'] > time()) { $votat = "true"; } else { if ($w['time'] .= "") { mysql_query("DELETE FROM votes WHERE id = '$id' AND ip = '$ipc'"); } }
$times = time()+86400;

if ($votat == "true") {
echo "Ati votat deja!";
$lvote1 = $vote1;
$lvote2 = $vote2;
} else {
if ($gvote == 1)
  {
  $lvote1 = $vote1 + 1;
setcookie("v_ $id", "cookieone", time()+3600);
  } else {
  $lvote1 = $vote1;
  }
if ($gvote == 2)
  {
  $lvote2 = $vote2 + 1;
setcookie("v_ $id", "cookieone", time()+3600);
  } else {
  $lvote2 = $vote2;
  }
mysql_query("INSERT INTO votes (id, ip, time) VALUES ('$id', '$ipc', '$times')");
}
echo "
<br>
$ipc<br>
$ips<br>
$i<br>
$votat
";

echo "<br>$vote1 $vote2<br>";
echo "$lvote1 $lvote2<br>";
mysql_query("UPDATE $table SET votes1 = '$lvote1', votes2 = '$lvote2' WHERE id = '$id'") or die("Eroare!, Update!");;
echo mysql_erorr();
?>