<?php
include ("inc/inc_connection.php");

$result = mysql_query( "SELECT * FROM $calendartable WHERE intId = $id" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    $day = $a_row->intDay;
    $month = $a_row->intMonth;
    $year = $a_row->intYear;
    $title = $a_row->strTitle;
}

$result = mysql_query( "SELECT * FROM $calendartable WHERE strTitle = '$title' AND intDay = '$cday' AND intMonth = '$cmonth' AND intYear = '$cyear' AND strName = '$gfcookie[1]'" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    $main = $a_row->ynMainRow;
}


if ( $main == 1 )
{
    $query = "UPDATE $calendartable SET strName = '' WHERE intId = '$id'";
}
else
{
    $query = "DELETE FROM $calendartable WHERE strTitle = '$title' AND intDay = '$cday' AND intMonth = '$cmonth' AND intYear = '$cyear' AND strName = '$gfcookie[1]'";
}


                mysql_query( $query, $link )
                or die ( "Could not delete from \"$calendartable\" table: "
        .mysql_error() );

       header("Location: eventmanager.php");
exit;