<?php
$q1 = @mysql_query( @"select  *  from  `forum_topic` where `id`='".$id."' ;" );
$topic = @mysql_fetch_array(@$q1);
if (mysql_affected_rows() == 0){
echo $fs1;
echo '<b>Такой темы не существует!</b>';
echo $fs2;
foot();
exit;
}

$vote = abs(intval($_POST['vote']));
$topic_vote = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_vote` WHERE `type`='2' AND `id`='$vote' AND `topic`='$id'"), 0);
$vote_user = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_vote_us` WHERE `user`='$row[id]' AND `topic`='$id'"), 0);

if ($topic_vote == 0 || $vote_user > 0 || $topic == 0) {
echo '<b>Ошибка голосования </b><br /> <a href="'.htmlspecialchars(getenv("HTTP_REFERER")).'">Вернуться</a>';
foot();
exit;
}
mysql_query("INSERT INTO `forum_vote_us` SET `topic`='".$id."', `user`='".$row['id']."', `vote`='".$vote."';");
mysql_query("UPDATE `forum_vote` SET `count` = count + 1 WHERE id = '".$vote."';");
mysql_query("UPDATE `forum_vote` SET `count` = count + 1 WHERE topic = '".$id."' AND `type` = '1';");
echo '<b>Ваш голос принят </b><br /> <a href="'.htmlspecialchars(getenv("HTTP_REFERER")).'">Вернуться</a>';
header("Location: ".F."tema/$id/end");

?>