Page 1 of 1

[SOLVED] Script not working properly.

Posted: Tue Nov 28, 2006 8:35 pm
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>
";
?>

Posted: Tue Nov 28, 2006 8:40 pm
by evilchris2003
Where is the PHP?

Posted: Tue Nov 28, 2006 8:48 pm
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.

Posted: Tue Nov 28, 2006 8:48 pm
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..

Posted: Tue Nov 28, 2006 8:52 pm
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?

Posted: Tue Nov 28, 2006 8:53 pm
by evilchris2003
because after the closing </html> tag you have HTML:

simply remove it

Posted: Tue Nov 28, 2006 8:55 pm
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.

Posted: Tue Nov 28, 2006 8:56 pm
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 ?>.

Posted: Tue Nov 28, 2006 9:00 pm
by evilchris2003
ah sorry my mistake ive never done that before

Re: Script not working properly.

Posted: Tue Nov 28, 2006 10:25 pm
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>

Re: Script not working properly.

Posted: Wed Nov 29, 2006 9:06 am
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?

Posted: Wed Nov 29, 2006 9:14 am
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

Posted: Wed Nov 29, 2006 9:21 am
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?

Posted: Wed Nov 29, 2006 11:03 am
by evilchris2003
exactly :D