<?php
include ("inc/inc_common.php");
include ("inc/inc_connect.php");

$rateid = $topicid;
if (isset($imageid))
{
    $rateid = $imageid;
}

if ($rate == "okay")
{
    $query = "INSERT INTO $ratedtable ( strName, intRateId) values( '$gfcookie[1]', '$rateid')";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
    header("Location: topic.php?topicid=$gobackto");
    exit;
}

$result=mysql_query("SELECT * FROM $forumtable WHERE intId = '$rateid'");
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    $rating = $a_row->intRating;
}

if ($rate == "bad")
{
    $rating -= 1;
}
if ($rate == "good")
{
    $rating ++;
}

$query = "UPDATE $forumtable SET intRating = '$rating' WHERE intId = '$rateid'";
mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );

$query = "INSERT INTO $ratedtable ( strName, intRateId) values( '$gfcookie[1]', '$rateid')";
mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
if ($gallery == 1)
{
    header("Location: gallerypicture.php?imageid=$imageid&groupid=$groupid&topicid=$topicid#bottom");
    exit;
}
header("Location: topic.php?topicid=$gobackto");
exit;