[SOLVED] Script not working properly.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ruud Hermans
Forum Newbie
Posts: 11
Joined: Tue Nov 28, 2006 8:33 pm

[SOLVED] Script not working properly.

Post by Ruud Hermans »

I'm pretty new to PHP. Could some one tell me why this script refuses to work?

I get an output but it does not display the image nore the menu witch is published as a list. I don't understand why not sinds it all works fine when I save it as a html document.

Code: Select all

<? php
print "<html>
<head>
<style type=\"text/css\">
#menu {
padding:0;
margin:0;
height:2em;
list-style-type:none;
border-left:1px solid #bbb;
}
#menu li {
float:left; 
width:7em; 
height:2em;
line-height:2em;
border-right:1px solid #bbb;
position:relative;
text-align:center;
}
#menu li a, #menu li a:visited {
display:block;
text-decoration:none; 
color:#000;
}
#menu li a span, #menu li a:visited span {
display:none;
}
#menu li a:hover {
border:0; /* needed to trigger IE */
color:#bbb;
}
#menu li a:hover span {
display:block;
width:5em;
height:2em;
text-align:center;
position:absolute; 
left:-2px; 
top:-3px; 
color:#000; 
cursor:pointer;
}
</style>
</head>
<body>
<table bgcolor=\"#FFFFFF\" width=\"100%\" height=\"17%\" border=\"0\">
<tr>
<td width=\"100%\" height=\"100%\" rowspan=\"1\" colspan=\"1\" background=\"images/bg_top.gif\"></td>
</tr>
<tr>
<td>
<ul id=\"menu\">
<li><a href=\"#nogo\">Home<span>Home</span></a></li>
<li><a href=\"#nogo\">Disclaimer<span>Disclaimer</span></a></li>
<li><a href=\"#nogo\">Restaurants<span>Restaurants</span></a></li>
<li><a href=\"#nogo\">Recepies<span>Recepies</span></a></li>
<li><a href=\"#nogo\">Dictioinary's<span>Dictioinary's</span></a></li>
<li><a href=\"#nogo\">Forums<span>Forums</span></a></li>
<li><a href=\"#nogo\">Statistics<span>Statistics</span></a></li>
</ul>
</td>
</tr>
</table>
</body>
</html>
";
?>
Last edited by Ruud Hermans on Thu Nov 30, 2006 8:38 am, edited 2 times in total.
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

Where is the PHP?
Ruud Hermans
Forum Newbie
Posts: 11
Joined: Tue Nov 28, 2006 8:33 pm

Post by Ruud Hermans »

evilchris2003 wrote:Where is the PHP?
I need to add it but I fisrt want this to work. At a later time I want the links to be displayed in a chosen language and for that I will be using PHP. This needs to become the header witch will be used in several files first.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

To make things simpler for you you could try using
' ' to surround the html, or even..

Code: Select all

<?
print <<<HTML
<html>
<head>
<style type="text/css">
#menu {
padding:0;
margin:0;
height:2em;
list-style-type:none;
border-left:1px solid #bbb;
}
#menu li {
float:left;
width:7em;
height:2em;
line-height:2em;
border-right:1px solid #bbb;
position:relative;
text-align:center;
}
#menu li a, #menu li a:visited {
display:block;
text-decoration:none;
color:#000;
}
#menu li a span, #menu li a:visited span {
display:none;
}
#menu li a:hover {
border:0; /* needed to trigger IE */
color:#bbb;
}
#menu li a:hover span {
display:block;
width:5em;
height:2em;
text-align:center;
position:absolute;
left:-2px;
top:-3px;
color:#000;
cursor:pointer;
}
</style>
</head>
<body>
<table bgcolor="#FFFFFF" width="100%" height="17%" border="0">
<tr>
<td width="100%" height="100%" rowspan="1" colspan="1" background="images/bg_top.gif"></td>
</tr>
<tr>
<td>
<ul id="menu">
<li><a href="#nogo">Home<span>Home</span></a></li>
<li><a href="#nogo">Disclaimer<span>Disclaimer</span></a></li>
<li><a href="#nogo">Restaurants<span>Restaurants</span></a></li>
<li><a href="#nogo">Recepies<span>Recepies</span></a></li>
<li><a href="#nogo">Dictioinary's<span>Dictioinary's</span></a></li>
<li><a href="#nogo">Forums<span>Forums</span></a></li>
<li><a href="#nogo">Statistics<span>Statistics</span></a></li>
</ul>
</td>
</tr>
</table>
</body>
</html>
HTML;
?>
Then you don't have to mess with all the slashes..
Ruud Hermans
Forum Newbie
Posts: 11
Joined: Tue Nov 28, 2006 8:33 pm

Post by Ruud Hermans »

I tried how you published the code but at the end of it it also ouputs:

Code: Select all

HTML; ?>
Why is this?
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

because after the closing </html> tag you have HTML:

simply remove it
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Must have an error somewhere, i just coped it again, and it works fine ->
evilchris2003 wrote:because after the closing </html> tag you have HTML:

simply remove it
Thats there on purpose..

But it should not output when done correctly.
Ruud Hermans
Forum Newbie
Posts: 11
Joined: Tue Nov 28, 2006 8:33 pm

Post by Ruud Hermans »

evilchris2003 wrote:because after the closing </html> tag you have HTML:

simply remove it
I can't believe I should delete it but for some reason I can't make it stop displaying the php closingtag ?>.
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

ah sorry my mistake ive never done that before
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: Script not working properly.

Post by volka »

Ruud Hermans wrote:<? php
There's a blank between <? and php
<? relies on short_open_tag=on, the default php.ini sets short_open_tag=off.
There's no need to print such a large static html "string", you can enter,leave and re-enter the php block many times. Everything outside a php block is sent as-is to the client.

Code: Select all

<html>
	<head>
		<style type="text/css">
			#menu {
				padding:0;
				margin:0;
				height:2em;
				list-style-type:none;
				border-left:1px solid #bbb;
			}
			#menu li {
				float:left;
				width:7em;
				height:2em;
				line-height:2em;
				border-right:1px solid #bbb;
				position:relative;
				text-align:center;
			}
			#menu li a, #menu li a:visited {
				display:block;
				text-decoration:none;
				color:#000;
			}
			#menu li a span, #menu li a:visited span {
				display:none;
			}
			#menu li a:hover {
				border:0; /* needed to trigger IE */
				color:#bbb;
			}
			#menu li a:hover span {
				display:block;
				width:5em;
				height:2em;
				text-align:center;
				position:absolute;
				left:-2px;
				top:-3px;
				color:#000;
				cursor:pointer;
			}
		</style>
	</head>
	<body>
		<table bgcolor="#FFFFFF" width="100%" height="17%" border="0">
			<tr>
				<td width="100%" height="100%" rowspan="1" colspan="1" background="images/bg_top.gif"></td>
			</tr>
			<tr>
				<td>
					<ul id="menu">
						<li><a href="#nogo">Home<span>Home</span></a></li>
						<li><a href="#nogo">Disclaimer<span>Disclaimer</span></a></li>
						<li><a href="#nogo">Restaurants<span>Restaurants</span></a></li>
						<li><a href="#nogo">Recepies<span>Recepies</span></a></li>
						<li><a href="#nogo">Dictioinary's<span>Dictioinary's</span></a></li>
						<li><a href="#nogo">Forums<span>Forums</span></a></li>
						<li><a href="#nogo">Statistics<span>Statistics</span></a></li>
					</ul>
				</td>
			</tr>
		</table>
		<?php echo date("F j, Y, g:i a"); ?>
		
	</body>
</html>
Ruud Hermans
Forum Newbie
Posts: 11
Joined: Tue Nov 28, 2006 8:33 pm

Re: Script not working properly.

Post by Ruud Hermans »

volka wrote:There's a blank between <? and php
<? relies on short_open_tag=on, the default php.ini sets short_open_tag=off.
There's no need to print such a large static html "string", you can enter,leave and re-enter the php block many times. Everything outside a php block is sent as-is to the client.
I knew the fist part so I also tried it using the <?php as opening tag.

However I get it displayed as php code without any tags but is this a good way ore should I avoid doing this?
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

what he means is there is no need to have your whole page processed by the PHP

you just need to put it where you need it in the page

look at the botom of the script Volka posted theres only 1 line processed using PHP and the rest is processed as HTML
Ruud Hermans
Forum Newbie
Posts: 11
Joined: Tue Nov 28, 2006 8:33 pm

Post by Ruud Hermans »

evilchris2003 wrote:what he means is there is no need to have your whole page processed by the PHP

you just need to put it where you need it in the page

look at the botom of the script Volka posted theres only 1 line processed using PHP and the rest is processed as HTML
Meaning I do not need to use any php opening ore closing tag when no php is inserted between it?
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

exactly :D
Post Reply