I need someone to help me with the following problem please:

First of all I have 3 (there are more, but only these 3 files are needed) files:
index.php (this file is composed of several other files with a .inc extension)
cfg_db_connect.php (contains the code to connect to a database. It does work it has been tested)
content.inc (this file is called from the index.php file and displays the content of a page in the web browser)

Here is the code for the file index.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<script type="text/javascript" src="dropdown.js"></script>
<link href="style.css" type="text/css" rel="stylesheet">
<link href="headerstyle.css" type="text/css" rel="stylesheet">
<title>DemoTech Home Page</title>
</head>
<body>

<?php readfile("header.inc");?>
[B]<?php readfile("content.inc");?>[/B]
<?php readfile("sidebar.inc");?>
</div>
<?php readfile("footer.inc");?>
</body>
</html>

Here is the code for the file cfg_db_connect.php:

<?php

function dbopen($hostname, $username, $password )
{
	$dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
	print "Connected to MySQL<br>";
	return $dbh;
}

function queryInfo()
{
	$result = mysql_query("SELECT nws_id, nws_title, nws_posted FROM news");
	while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
	print "ID:".$row{'nws_id'}." Title:".$row{'nws_title'}." Posted:".$row{'nws_posted'}."<br>";
	}

	return $result;
}

function queryInfo2()
{
	$result = mysql_query("SELECT nws_title, nws_content, nws_posted FROM news");
	while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
	print "<div class=\"post\">
			<h2 class=\"title\">
				Title:".$row{'nws_title'}."
			</h2>
	       <div class=\"entry\">
			".$row{'nws_content'}."
	       </div>
	       <p class=\"meta\"><span class=\"byline\">Posted by ".$row{'nws_posted'}." on December 22, 2007</span><a href=\"#\" class=\"comments\">18 comments</a></p>
	       
	       </div><br>";
	}

	return $result;
}

function dbclose($dbh)
{
	mysql_close($dbh);	
}
?>

Here is the code for the file content.inc:

<HEAD>
<link href="style.css" type="text/css" rel="stylesheet">
</HEAD>

<div id="content-wrapper">
	<div id="content">
		<div class="post">
									
				<?PHP

				include ("cfg_db_connect.php");
			
				$username = "xxxx";
				$password = "xxxx";
				$hostname = "xxxx";
				$database = "xxxx"

				$connect=dbopen($hostname, $username, $password);

				//a database must be selected first
				$selected = mysql_select_db($database,$connect) or die("Could not select first_test");
	
				queryInfo2();

				dbclose($connect);

				?>			
		</div>
	</div>
</div>

Now the problem:
For some reason when I try to run the above files together, the results of the query from the database does not display in the index.php file when the index.php file is run at the server side.

But...

When the code of the file content.inc is copied to the file called index.php, the query seems to be working fine (meaning it displays the contents correctly to the web page), but I don't want to do it this way, because I want the contents to exist in separate files.

Is it possible for someone to explain to me why this is happening?

Thanks in advance

what happens if you change your readfile() to include() in your index.php? or require()

Thanks for the suggestion, but I got the following error message:
Parse error: parse error in C:\Program Files\xampp\webdav\content.inc on line 18

Thanks for pointing out that semi-colon. That didn't solve my problem.

I use Netbeans on a regular basis, but struggle to get it to work with the web server, and therefore it was decided to use a text editor instead. I know this is not the best way to go, but it is good for now.

include ("cfg_db_connect.php");
should be

require ("cfg_db_connect.php");

it's probably not going to fix your problem, but it will probably display an error that shows you the problem. Also, it should be required, not included anyway. It's necessary code.

and there shouldnt be any "struggling to get netbeans to work with the web server" as it's an editor, just the same as whatever other editor you are using.

there's an edit button, but I believe you are only allowed to edit for a certain amount of time. Then that button and functionality is disabled.

Hi everyone.

Thank you very much for everyone's feedback. I managed to get it to work by carefully looking at the code again and the way it was managed.

This question has already been answered. Start a new discussion instead.