PDA

View Full Version : Problems with PHP includes?


FethrdWlf
02-19-2011, 06:04 AM
So, I'm making a website for testing reasons regarding PHP and MySQL (project-php.zxq.net (http://project-php.zxq.net/)).

I would like to have a sidebar (Click here to see it (http://project-php.zxq.net/sidebar.php)) added using the php includes stuff. BUT, it will never work for me.

The code looks like this with the includes:
<body>
<div id="navigation"><?php include("sidebar.php"); ?></div>
<div id="wrapper">
<div id="header"><a href="index.html"><img src="images/logo.png" alt="logo" width="200" height="100" border="0" /></a> </div>
<div id="mainbody">
<div id="textwrap">.................................................. ................
</div>
</div>
<div id="footer"></div>
................................
</body>

But instead, it just replaces everything with the content of the sidebar, no CSS, and no index page. Only the sidebar. How can I get around that?:confused:

Corrosive
02-19-2011, 08:28 AM
Most of this code in your sidebar needs to go;



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body,td,th {
color: #F3F3F3;
font-family: Tahoma, Geneva, sans-serif;
}
body {
background-image: url(images/sidebar-navigation.PNG);
background-repeat: no-repeat;
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
}
-->
</style>
<link href="css/sidebar.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper">
<p>Content will <em>eventually</em> make it's way here, but not yet.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
</body>
</html>

Because you now have two sets of head tags, two sets of body tags etc. Read this tutorial again; http://www.dreamweaverclub.com/php-includes.php Your code for the include file should look more like;


<p>Content will <em>eventually</em> make it's way here, but not yet.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>


and then just add your sidebar styles to your main stylesheet.

FethrdWlf
02-19-2011, 08:23 PM
Thank you Corrosive! It worked beautifully! I owe you one dude.

Corrosive
02-20-2011, 06:38 AM
Thank you Corrosive! It worked beautifully! I owe you one dude.

You are welcome. No need for an 'owe' just stick around and help others :) Makes the world go round!