<?php
include ("inc/inc_connect.php");
$result = mysql_query( "SELECT * FROM $calendartable WHERE intId = $id" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    $cday = $a_row->intDay;
    $cmonth = $a_row->intMonth;
    $cyear = $a_row->intYear;
    $title = $a_row->strTitle;
    $author = $a_row->author;
    $ctime = $a_row->intTime;
    $message = $a_row->memMessage;
    $eventid = $a_row->intEventId;
    $sport = $a_row->ynSport;
    $home = $a_row->strHomeTeam;
    $away = $a_row->strAwayTeam;
    $league = $a_row->strLeague;
    $post = $a_row->intTopicId;
}

//Check to make sure you're not already inserted...

$result = mysql_query( "SELECT * FROM $calendartable WHERE intDay = '$cday' AND intMonth = '$cmonth' AND intYear = '$cyear' AND strName = '$gfcookie[1]' AND strTitle = '$title'" );
$num_rows = mysql_num_rows( $result );
if ($num_rows > 0)
{
    //already inserted
    header("Location: calendardayall.php?cday=$cday&cmonth=$cmonth&cyear=$cyear&alreadyinserted=YES");
    exit;
}

// add to the forum if the id is set...

if ( $post > 0 )
{
    $result = mysql_query( "SELECT * FROM $forumtable WHERE intTopicId = '$post' AND ynTopicRow = 'Yes'" );
    $num_rows = mysql_num_rows( $result );
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        $groupid = $a_row->intForumId;
        $topictitle = $a_row->strTopicName;
    }



    $topicid = $post;
    $tsttxt = $gfcookie[1]." has signed up for this event.";
    include ("add_calendar_reply.php");
}



$query = "INSERT INTO $calendartable ( strName, strAuthor, strTitle, intDay, intMonth, intYear, intTime, ynMainRow, memMessage, intEventId, ynSport, strHomeTeam, strAwayTeam, strLeague, intTopicId ) values( '$gfcookie[1]', '$author', '$title', '$cday', '$cmonth', '$cyear', '$ctime', '0', '$message', '$eventid', '$sport', '$home', '$away', '$league', '$post' )";

mysql_query( $query, $link ) or die ( "Could not add data to \"$calendartable\" table as I can't spell: " .mysql_error() );

       header("Location: calendardayall.php?cday=$cday&cmonth=$cmonth&cyear=$cyear");
exit;