Duplicate code being displayed when viewing source in browser - causing styling issue

Hi all,

I am working with PHP & MYSQL NOVICE TO NINJA - BY KEVIN YANK

I have a profile system set up and it is all working fine. However I am trying to do some other styling around the page and have noticed that when I go to view source, the entire page code is duplicated. It is only duplicated once but none the less there is an exact copy of the code. The page on which this behavior is being seen is the one that displays the actual profiles.

This is preventing me from styling some other areas and I need to understand why this is happening.

I have posted some code below and can confirm that when I am on the page for which I am seeing the duplicate code, if I take the following out of the controller then it works again as in no duplicate code is seen:

include 'searchform.html.php';

This code is however obviously needed for my site but it does prevent a duplicate copy of the code being seen if removed so maybe it might provide a clue to the problem?

I’ve included the code which I believe is relevant.

INDEX.PHP (EXTRACT)

		// BUILDING THE PLAYER NAME DROP DOWN BOX FOR SEARCHING

		include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';

		try
		{
			$result = $pdo->query("SELECT id, name, position
								   FROM player INNER JOIN playerrole
								   ON player.id = playerid
								   WHERE roleid = 'Player'
								   ORDER BY position, name");
								
		}
		catch (PDOException $e)
		{
			$error = 'Error fetching player names from database!' . $e->getMessage();
			include 'error.html.php';
			exit();
		}
		// Added age to here to get it as a value under the search results heading and had to put it in above select query
		foreach ($result as $row)
		{
			$names[] = array('id' => $row['id'], 'name' => $row['name'], 'position' => $row['position']);
		}

        include 'searchform.html.php';

		// SQL STATEMENT THAT PERFORMS THE SEARCH

		if (isset($_GET['action']) and $_GET['action'] == 'search')
		{
			include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
			
				$id = $_GET['name'];
				$text = $_GET['text'];

			$params = '';

			if($id !== '')
			{
				$params = "player.id = '$id'";
			}
			else if($text !== '')
			{
				$params = "player.name LIKE '%$text%'";
			}
			else if($id == '')
			{
				$selectError = 'Please either select a name from the drop down list or enter the name of a player';
			}
				
			try
			{

			$sql = "SELECT player.id, player.name AS name, age, position, height, weight, previousclubs.name AS previousclubs,
					satscore, gpa, link, email
					FROM player INNER JOIN playerpreviousclubs
						ON player.id = playerid
					INNER JOIN previousclubs
						ON previousclubid = previousclubs.id
					INNER JOIN links
						ON links.playerid = player.id
					WHERE {$params}";
			
			$s = $pdo->query($sql);
			}
			catch (PDOException $e)
			{
				$error = 'You have not selected or entered a name.' /*. $e->getMessage()*/;
				include 'error.html.php';
				exit();
			}
			// This is responsible for populating the new player info underneath all
			foreach ($s as $row)
			{
				$results[] = array(
									'id' => $row['id'],
									'name' => $row['name'],
									'age' => $row['age'],
									'position' => $row['position'],
									'height' => $row['height'],
									'weight' => $row['weight'],
									'satscore' => $row['satscore'],
									'gpa' => $row['gpa'],
									'previousclubs' => $row['previousclubs'],
									'links' => explode(',',$row['link']),
									'email' => $row['email']
									);
			}
			include 'profiles.html.php';
			exit();
		}

SEARCHFORM.HTML.PHP (EXTRACT)

		<div id="Profile" class="Profile"  >

		<h1>Player Profile Search</h1>

		<p>Please either select a name from the drop down box or enter part of the name into the search field and click the search button.</p>

		<form action="" method="get">

		<ol>

		<li class="bold"><label for="name">By Position / Name:</label></li>

		<li>
		<select name="name" id="name">
		<option value="">Position / Name</option>
		<!-- populates the drop down with names -->
		<?php foreach ($names as $name): ?>
		<option value="<?php htmlout($name['id']); ?>">
		<?php htmlout($name['position']); ?> / <?php htmlout($name['name']); ?>
		</option>
		<?php endforeach; ?>
		<?php if (isset($selectError)): ?>
		<p><?php htmlout($selectError); ?></p>
		<?php endif; ?>
		</select>
		</li>

		<li class="bold"><label for="text">Containing text:</label></li>
		<li><input type="text" name="text" id="text"></li>

		<li><input type="hidden" name="action" value="search"></li>
		<li><input type="submit" value="Search" class="button search"></li>

		</ol>

		</form>

		<!--<p class="return"><a href="..">Return to JMS home</a></p>-->
		<li class="logout"><?php include '../includes/logout.inc.html.php'; ?></li>

		</div>

PROFILES.HTML.PHP (EXTRACT)

		<div id="Profile" class="Profile"  >

		<h1 class="margin-top">Search Results</h1>

		<?php if (isset($results)): ?>

		<?php foreach ($results as $result): ?>

		<ol class="coach-display">

		<li class="left image"><img src="<?php echo('?action=view&id=' . $result['id']); ?>" width="180" height="240" /></li>

		<li class="listleft">Name:</li>
		<li><?php htmlout($result['name']); ?></li>

		<li class="listleft">Age:</li>
		<li><?php htmlout($result['age']); ?></li>

		<li class="listleft">Position:</li>
		<li><?php htmlout($result['position']); ?></li>

		<li class="listleft">Height:</li>
		<li><?php htmlout($result['height']); ?></li>

		<li class="listleft">Weight:</li>
		<li><?php htmlout($result['weight']); ?></li>

		<li class="listleft">Sat Score:</li>
		<li><?php htmlout($result['satscore']); ?></li>

		<li class="listleft">GPA:</li>
		<li><?php htmlout($result['gpa']); ?></li>

		<li class="listleft">Previous Clubs:</li>
		<li><?php htmlout($result['previousclubs']); ?></li>

		<li class="listleft">Email:</li>
		<li><a href="mailto:<?php htmlout($result['email']); ?>"><?php htmlout($result['email']); ?></a></li>

		<li class="listleft">Links:</li>
		<?php foreach($result['links'] as $link)
		{
			$link = trim($link);
			echo '<li class="inline"><a href="http://'.$link.'"target="_blank">'.$link.'</a></li>';
		}
		?>


		</ol>

		<form action="?" method="post">

		<div id="buttons">


		</div>
		</form>

		<?php endforeach; ?>

		<?php endif; ?>

		<h3 class="bold"><a href="?">New search</a></h3>
		<li class="logout"><?php include '../includes/logout.inc.html.php'; ?></li>

		</div>

Thanks for any help that you can provide.