<?php
include "config.php";
if(!empty($_POST['id_answer']))
{
$id_answer = $_POST['id_answer'];
$forward = getenv(HTTP_X_FORWARDED_FO R);
$ip = urldecode(getenv(HTTP_CLIENTIP));
if (($forward != NULL)&&($forward != $REMOTE_ADDR)) $ip = $ip."/".$forward;
$isip = "SELECT * FROM poll_ip
WHERE ip='$ip'
AND puttime>date_sub(now(), interval '2' minute)";
$ipresult = mysql_query($isip);
$delip = "DELETE FROM poll_ip
WHERE puttime<date_sub(now(),interval '2' minute)";
mysql_query($delip);
if($ipresult)
{
if(mysql_num_rows($ipresult)<1)
{
mysql_query("INSERT INTO poll_ip VALUES(0,'$ip',now())");
$query = "select hit from answer where id_answer=$id_answer";
$num = mysql_query($query);
if($num)
{
$number = mysql_fetch_array($num);
$query = "UPDATE answer SET hit=".($number['hit']+1)." WHERE id_answer=$id_answer";
mysql_query($query);
} else puterror("Ошибка при обращении к блоку голосования");
}
}
}
$pol = mysql_query("SELECT * FROM poll WHERE archive=0 AND hide=0");
if ($pol)
{
$poll = mysql_fetch_array($pol);
echo $poll['name']."<br>";
$query = "SELECT * FROM answer
WHERE id_poll=".$poll['id_poll']."
ORDER BY pos";
$total = "SELECT SUM(hit) FROM answer WHERE id_poll=".$poll['id_poll'];
$ans = mysql_query($query);
$tot = mysql_query($total);
if($ans && $tot)
{
$totl = mysql_fetch_array($tot);
$totalhits = $totl['SUM(hit)'];
if($totalhits == 0) $totalhits = 1;
echo "<table>";
while($answer = mysql_fetch_array($ans))
{
echo "<tr>
<td>".$answer['name']."</td>
<td>".$answer['hit']."</td>
<td>".sprintf("%01.1f%s", $answer['hit']/$totalhits*100,'%')."</td>
</tr>";
}
echo "</table>";
echo "Общее число проголосовавших составляет: ".$totl['SUM(hit)']."<br>";
echo "<a href=archive.php>Архив голосований</a><br>";
} else puterror("Ошибка при обращении к блоку голосования");
} else puterror("Ошибка при обращении к блоку голосования");
?>
and the config file is
<?php
$dblocation = "localhost";
$dbname = "poll";
$dbuser = "root";
$dbpasswd = "0000";
$version = "2.0.1";
$dbcnx = @mysql_connect($dblocation,$dbuser,$dbpasswd);
if (!$dbcnx) {
echo( "<P>В настоящий момент сервер базы данных не доступен, поэтому корректное отображение страницы невозможно.</P>" );
exit();
}
if (! @mysql_select_db($dbname,$dbcnx) ) {
echo( "<P>В настоящий момент база данных не доступна, поэтому корректное отображение страницы невозможно.</P>" );
exit();
}
function puterror($message)
{
echo("<p>$message</p>");
exit();
}
?>
when i add this code to the template index.php it don't work

but when i saved it in php file and opened it it works.
please tell me what the problem is..