Page 1 of 1

how do i display a file on a page

Posted: Thu Nov 19, 2009 7:55 am
by chris_s_22
this is my page im using as you can see i use include so i only after edit one page if i need to make changes in the future.

Code: Select all

<?php 
include_once 'Connect.php';
?>
<html><head>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
 
<body>
<div class=logo><?php include "logo.php";?></div>
 
<div class=navigationbarbox><?php include "navigationbar.php";?></div>
 
<div class=welcome>License detilas here</div>
 
<div class=footerbox><?php include "footer.php";?></div>
</body>
</html>
however i want this page to dispaly another navigationbar if not logged in. i thought i just have to do a call to my is_authed function and then display the correct one
<?php
if (!is_authed())
{
echo "<div class=navigationbarbox><?php include "navigationbar.php";?></div>";
}
else
{
echo "<div class=navigationbarbox><?php include "navigationbar2.php";?></div>";
}
?>
i think the problem is my echo statements can anyone tell me what i should be doing

Re: how do i display a file on a page

Posted: Thu Nov 19, 2009 8:04 am
by iankent
chris_s_22 wrote:

Code: Select all

 
<?php
if (!is_authed()) 
{
     echo "<div class=navigationbarbox><?php include "navigationbar.php";?></div>";
}
else
{
    echo "<div class=navigationbarbox><?php include "navigationbar2.php";?></div>";
}
?>
 
i think the problem is my echo statements can anyone tell me what i should be doing
You're right, it is your echo statements. You can't use <? and ?> within echo statements because echo statements are, by their nature, already within PHP. You'd need to do this instead:

Code: Select all

 
<?php
if (!is_authed()) 
{
     echo "<div class=navigationbarbox>";
     include "navigationbar.php";
     echo "</div>";
}
else
{
     echo "<div class=navigationbarbox>";
     include "navigationbar2.php";
     echo "</div>";
}
?>
 
edit: what do you use to edit your PHP files? if you just use notepad or similar, consider getting a code editor that gives syntax highlighting, and if you use something like NuSphere it even gives you design-time debugging. Makes it much easier to spot errors, as in this case the include() keywords weren't highlighted when they should be, an indicator that they aren't going to work!

Re: how do i display a file on a page

Posted: Thu Nov 19, 2009 8:45 am
by chris_s_22
yeah i normally use dreamweaver though not at home so using notepad

but thanks working has it should now