simple12 0 Newbie Poster

Hello

I have a script which have the facility of entering any code to some part of a webpage. I have some
some problems with it. When i put some code in the script then their is no error shown. When i try to
not use a code and leave it empty the following php errors happens. I dont understand why. Help me.

Error shown are: -

[phpBB Debug] PHP Notice: in file /index.php on line 132: Undefined offset: 4
[phpBB Debug] PHP Notice: in file /index.php on line 141: Undefined offset: 4
[phpBB Debug] PHP Notice: in file /index.php on line 142: Undefined offset: 5
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4250: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3730)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4252: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3730)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4253: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3730)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4254: Cannot modify header information - headers already sent by (output started at /includes/functions.php:3730)


Error script part

// Start output Ad
$aktiv = ($user->data['user_id'] != ANONYMOUS) ? '1' : '3';

$sql = "SELECT code, ID, position FROM " . AD_TABLE ." 
	WHERE (activ = '" .$aktiv. "' OR activ = '1')
	AND  (max_views <= views)
	AND (show_all_forums = '1')
	ORDER BY rand()	";

$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result))
{
	$adcode[$row['position']] = html_entity_decode($row['code']);
	$adID[$row['position']]['ID'] = $row['ID'];
}

// update views for every Ad
for ($i = 1; $i <= 4; $i++)
{
	if ($adID[$i]['ID'])     // line 132 error line
	{
		$db->sql_query('UPDATE ' . AD_TABLE . ' SET views = views +1 WHERE ID = ' . $adID[$i]['ID']);
	}
}
// End output Ad

// Assign index specific vars
$template->assign_vars(array(
      'AD_CODE4'      => $adcode[4],   //line 141 error line
	'AD_CODE5'      => $adcode[5],   //line 142 error line
	'TOTAL_POSTS'	=> sprintf($user->lang[$l_total_post_s], $total_posts),
	'TOTAL_TOPICS'	=> sprintf($user->lang[$l_total_topic_s], $total_topics),
	'TOTAL_USERS'	=> sprintf($user->lang[$l_total_user_s], $total_users),