Solved

why doesn't this php code work

Posted on 2003-12-05
15
320 Views
Last Modified: 2008-03-06
I'm a first timer here.  I've searched through several other people's quesitons that are similar but I cannot figure out why this doesn't work.

<HTML>
<HEAD>
<TITLE> My First Php page </TITLE>
<LINK rel="stylesheet" type="text/css" href="style.css">
</HEAD>

<BODY>
<?php
include("head.html");
?>
<!-- Table for Main Body -->
<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td valign=top align=left width="90">
<?php
include ("menu.html");
?>
</td>
<td width="1" bgcolor="blue" valign=top>  </td>
<td valign=top>

<?php
include ("page1body.html");
?>
<br> <br>
<?php
include ("menu2.html");
?>
</td>
<td width="1" bgcolor="blue" valign=top>   </td>
</tr></table>

</BODY></HTML>
0
Comment
Question by:AWP
  • 6
  • 5
  • 4
15 Comments
 
LVL 6

Expert Comment

by:rjdown
Comment Utility
The HTML and PHP tags appears to be correct, please be more specific. What do you mean "it doesn't work"?

Are the include pages in the same directory as your main page?
0
 
LVL 6

Expert Comment

by:rjdown
Comment Utility
Hmm as an afterthought, are you sure PHP is installed on your server?
0
 

Author Comment

by:AWP
Comment Utility
I know that one of my other domains uses a php shopping cart and it works fine.  I've also noticed that is has a mysql database configurd with it.  I am not sure that I have everything configured properly on this domain.  But the server has it installed properly.
0
 

Author Comment

by:AWP
Comment Utility
the include pages are in the same directory as the main page.

When I say it doesn't work I mean that when I pull up the index.php all I see is a white page with 2 blue likes that are the background colors for he left and right margins.  No header, no footer, no body comes up.
0
 
LVL 6

Expert Comment

by:rjdown
Comment Utility
Could you post the contents of one or all of your includes here. The problem may lie within those.
0
 

Author Comment

by:AWP
Comment Utility
the menu.html


<html>

<head>


<title>New Page 5</title>
</head>

<body>

[<a href="index.php">Home </a>]
[<a href="page2.php">Page 2</a>]
[<a href="page3.php">Page 3</a>]
[<a href="page4.php">Page 4</a>]


</body>

</html>


I looked at one tutorial that said to leave out the html & body tags on the includes pages.  I've tried that also and I received the same response.
0
 
LVL 6

Expert Comment

by:rjdown
Comment Utility
Indeed you should leave out html, head, title and body tags, but this is simply good practice and will not affect your output.

I have put your code onto my server and it works fine. Can you try this in your index.php:

replace

include("menu.html");

with

echo "menu.html";

and likewise with the other includes.

This is just a test to make sure your PHP engine is working, and will simply print the text "menu.html" for example, instead of the actual menu.

If it works, there is a problem with your PHP settings, and I will explain further what you need to do.
If it doesn't work, your PHP engine is either broken or missing.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:HeadAcheMike
Comment Utility
your include tags are wrong should be

include('file.html');

Not

include("file.html")
0
 
LVL 2

Accepted Solution

by:
HeadAcheMike earned 500 total points
Comment Utility
try it like this, should fix your problem:

<HTML>
<HEAD>
<TITLE> My First Php page </TITLE>
<LINK rel="stylesheet" type="text/css" href="style.css">
</HEAD>

<BODY>
<?php
include('head.html');
?>
<!-- Table for Main Body -->
<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td valign=top align=left width="90">
<?php
include ('menu.html');
?>
</td>
<td width="1" bgcolor="blue" valign=top>  </td>
<td valign=top>

<?php
include ('page1body.html');
?>
<br> <br>
<?php
include ('menu2.html');
?>
</td>
<td width="1" bgcolor="blue" valign=top>   </td>
</tr></table>

</BODY></HTML>
0
 
LVL 6

Expert Comment

by:rjdown
Comment Utility
" and ' are both valid..at least on my box (PHP version 4.3.3)
0
 
LVL 2

Expert Comment

by:HeadAcheMike
Comment Utility
i had once assumed that but ive come accross a couple of people who have had problems with the double quote, worth trying nevertheless
0
 
LVL 6

Expert Comment

by:rjdown
Comment Utility
Fair nuff :D
0
 

Author Comment

by:AWP
Comment Utility
it still appears the same.  how do i confirm if php is properly installed on the domain?
0
 
LVL 2

Expert Comment

by:HeadAcheMike
Comment Utility
put this in a file and exeucute it

<?php
php_info();
?>

if it is installed then it will give you all of the php installation information
0
 
LVL 2

Expert Comment

by:HeadAcheMike
Comment Utility
and one other thing if you are not aware of this, any files that contain php code must have the extension .php instead of .html
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now