Page 1 of 1
Code displaying in HTML Page
Posted: Wed Oct 13, 2004 4:56 pm
by bobbyaa
I am creating a website where I want the basis of the page to be html with the code imbedded within. I am running into a problem that some of my PHP scripting is displaying as text on the HTML page. I have checked escaping my quotes, etc. any ideas? If you are curious as to what it looks like...here :
http://www.ipdinfo.org
Robert
Posted: Wed Oct 13, 2004 5:01 pm
by kettle_drum
And which part is the php code? I dont see any. Just remember:
Code: Select all
Out of php
<?php
//inside of php
echo "inside";
?>
outside
Posted: Wed Oct 13, 2004 5:06 pm
by bobbyaa
Its all inside the PHP beginning and ending markers. ive gone back and checked all of the quotation marks and i am still getting a problem. If you view the page source it is near the bottom.
Posted: Wed Oct 13, 2004 5:08 pm
by partiallynothing
Can you go ahead and post the entire page's source code? That would make this much easier.
Posted: Wed Oct 13, 2004 5:09 pm
by bobbyaa
Sami | Help us, help you. Please use Code: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
I know some of the variables are off towards the mid of the php scripting....thats not the issue...the issue arises very early in the script.
Code: Select all
<?php
<html>
<head>
<style type="text/css">
<!--
body,td,input { font-family: tahoma, helvetica; font-size: 11px; color: #B9B9B9; line-height: 18px; }
body { background-image: url('i/a1.jpg'); }
form { margin: 0px; }
a { text-decoration: none; color: #ffffff;}
a:hover { text-decoration: underline; color: #ffffff;}
.left { font-weight: bold; font-size: 10px; color: #ffffff; }
.emph { color: #ffffff; font-weight: bold; }
.nav { color: #666666; }
-->
</style>
</head>
<body rightmargin="0" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" rightmargin="0">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<img src="i/spacer.gif" width="1" height="22">
</td>
</tr>
<tr>
<td style="background-image: url('i/a5.jpg'); background-repeat: repeat-x"><a href="http://www.ipdinfo.org/"><img border="0" src="i/a4%20copy.jpg" width="772" height="139"></a></td>
</tr>
<tr>
<td style="background-image: url('i/a6.jpg'); background-repeat: repeat-x">
<table width="903" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="17"><img src="i/spacer.gif" width="16" height="1"></td>
<td width="99">
<p align="center"><img src="i/spacer.gif" width="16" height="1">
<a class=nav href="#">Repo Log</a><img src="i/spacer.gif" width="16" height="1"></p>
</td>
<td width="23"><img src="i/a8.jpg"></td>
<td width="104"><img src="i/spacer.gif" width="16" height="1">
<a class=nav href="#">Apt Guide</a><img src="i/spacer.gif" width="16" height="1">
</td>
<td width="23"><img src="i/a8.jpg"></td>
<td width="88"><img src="i/spacer.gif" width="16" height="1">
<a class=nav href="#">Vacation Watches</a><img src="i/spacer.gif" width="16" height="1">
</td>
<td width="24"><img src="i/a8.jpg"></td>
<td width="119"><img src="i/spacer.gif" width="16" height="1">
<a class=nav href="http://pound.ipdinfo.org">Pound Log</a><img src="i/spacer.gif" width="16" height="1">
</td>
<td width="26"><img src="i/a8.jpg"></td>
<td width="114"><img src="i/spacer.gif" width="16" height="1">
<a class=nav href="http://www.ipdinfo.org/pound/users.php">Database Users</a>
<img src="i/spacer.gif" width="16" height="1"></td>
<td width="24"><img src="i/a8.jpg"></td>
<td width="62"><img src="i/spacer.gif" width="16" height="1">
<a class=nav href="#">Admin</a><img src="i/spacer.gif" width="16" height="1">
</td>
<td width="154"><img src="i/spacer.gif"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="background-image: url('i/a19.jpg'); background-repeat: repeat-x"><img src="i/a19.jpg"></td>
</tr>
<tr>
<td style="background-image: url('i/a34.jpg')">
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="background-image: url('i/a28.jpg'); background-repeat: repeat-x">
<tr>
<td><img src="i/spacer.gif" width="9" height="1"></td>
<td valign="top">
<table cellpadding="0" cellspacing="0" border="0" width="166">
<tr>
<td colspan="4"><img src="i/spacer.gif" width="1" height="35"></td>
</tr>
<tr>
<td width="149" align="right">
<a href="#" class="left">FIRST PAGE LINK</a>
</td>
<td><img src="i/spacer.gif" width="11" height="34"></td>
<td><img src="i/a90.jpg"></td>
<td><img src="i/spacer.gif" width="2" height="1"></td>
</tr>
<tr>
<td colspan="4"><img src="i/a37.jpg"></td>
</tr>
<tr>
<td width="149" align="right">
<a href="#" class="left">SECOND PAGE LINK</a>
</td>
<td><img src="i/spacer.gif" width="11" height="34"></td>
<td><img src="i/a90.jpg"></td>
<td><img src="i/spacer.gif" width="2" height="1"></td>
</tr>
<tr>
<td colspan="4"><img src="i/a37.jpg"></td>
</tr>
<tr>
<td width="149" align="right">
<a href="#" class="left">THIRD PAGE LINK</a>
</td>
<td><img src="i/spacer.gif" width="11" height="34"></td>
<td><img src="i/a90.jpg"></td>
<td><img src="i/spacer.gif" width="2" height="1"></td>
</tr>
<tr>
<td colspan="4"><img src="i/a37.jpg"></td>
</tr>
<tr>
<td width="149" align="right">
<a href="#" class="left">FOURTH PAGE LINK</a>
</td>
<td><img src="i/spacer.gif" width="11" height="34"></td>
<td><img src="i/a90.jpg"></td>
<td><img src="i/spacer.gif" width="2" height="1"></td>
</tr>
<tr>
<td colspan="4"><img src="i/a37.jpg"></td>
</tr>
<tr>
<td width="149" align="right">
<a href="#" class="left">FIFTH PAGE LINK</a>
</td>
<td><img src="i/spacer.gif" width="11" height="34"></td>
<td><img src="i/a90.jpg"></td>
<td><img src="i/spacer.gif" width="2" height="1"></td>
</tr>
<tr>
<td colspan="4"><img src="i/a37.jpg"></td>
</tr>
<tr>
<td width="149" align="right">
<a href="#" class="left">SIXTH PAGE LINK</a>
</td>
<td><img src="i/spacer.gif" width="11" height="34"></td>
<td><img src="i/a90.jpg"></td>
<td><img src="i/spacer.gif" width="2" height="1"></td>
</tr>
</table>
</td>
<td><img src="i/spacer.gif" width="9" height="1"></td>
<td style="background-image: url('i/a26.jpg'); background-repeat: repeat-y"><img src="i/a26.jpg"></td>
<td><img src="i/spacer.gif" width="23" height="1"></td>
<td width="100%" valign="top">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td><img src="i/spacer.gif" width="1" height="35"></td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td><img src="i/a33.jpg"></td><td><h2>News</h2></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><img src="i/spacer.gif" width="1" height="22"></td>
</tr>
<tr>
<td>
<?
//include connection script
include('./connect.php');
//specify query to be run
$query="SELECT start,title,news FROM news WHERE (start>=CURDATE() AND end<=CURDATE()) ORDER BY 'start' DESC";
//assign query result to variable
$result=mysql_query($query);
//display data in the users table
if ($result) { //check to see if result returns
//display table header row
echo '<table align="left" cellspacing="0" cellpadding="2" border="0">';
//assign number of rows to variable for loop
$num=mysql_numrows($result);
//begin loop to display data in each row
for ($i=0; $i<$num; $i++){
//assign values to variables within loop to display
$id=mysql_result($result,$i,"id");
$fname=mysql_result($result,$i,"first");
$lname=mysql_result($result,$i,"last");
$rank=mysql_result($result,$i,"rank");
echo "<tr><td align="center"> $id </td>";
echo "<td align="center"> $lname, $fname </td>";
echo "<td align="center">$rank</td></tr>";
}
//print end of table
echo '</table>';
//release memory used by query
mysql_free_result($result);
} else {
//error with getting query
echo '<p>Users could not be displayed</p>';
}
mysql_close();
?>
<br>
<br>
</td>
</tr>
</table>
</td>
<td><img src="i/spacer.gif" width="60" height="1"></td>
</tr>
</table>
<br>
</td>
</tr>
<tr>
<td style="background-image: url('i/a38.jpg'); background-repeat: repeat-x"><img src="i/a38.jpg"></td>
</tr>
<tr>
<td align="center">
Copyright © 2004 <a href="http://www.ipdinfo.org">ipdinfo.org</a>. All rights reserved. Hosting provided by <a href="http://www.xenhosting.com">XenHosting.com</a>
</td>
</tr>
</table>
</body>
</html>
?>
Posted: Wed Oct 13, 2004 5:16 pm
by kettle_drum
Please use the tags to put your code so it looks pretty and it might catch the error.
You dont have to keep calling echo on each line:
Code: Select all
echo "
this is
just
as
good
or
add
newlines /n
/n
";
Then try to escape from the string before you print the vars, like:
Posted: Wed Oct 13, 2004 5:18 pm
by partiallynothing
Always place your code in the [*php][*/php] (minus the *s) tags, so it is nicely highlighted.
Code: Select all
<html>
<head>
<style type="text/css">
<!--
body,td,input { font-family: tahoma, helvetica; font-size: 11px; color: #B9B9B9; line-height: 18px; }
body { background-image: url('i/a1.jpg'); }
form { margin: 0px; }
a { text-decoration: none; color: #ffffff;}
a:hover { text-decoration: underline; color: #ffffff;}
.left { font-weight: bold; font-size: 10px; color: #ffffff; }
.emph { color: #ffffff; font-weight: bold; }
.nav { color: #666666; }
-->
</style>
</head>
<body rightmargin="0" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" rightmargin="0">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<img src="i/spacer.gif" width="1" height="22">
</td>
</tr>
<tr>
<td style="background-image: url('i/a5.jpg'); background-repeat: repeat-x"><a href="http://www.ipdinfo.org/"><img border="0" src="i/a4%20copy.jpg" width="772" height="139"></a></td>
</tr>
<tr>
<td style="background-image: url('i/a6.jpg'); background-repeat: repeat-x">
<table width="903" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="17"><img src="i/spacer.gif" width="16" height="1"></td>
<td width="99">
<p align="center"><img src="i/spacer.gif" width="16" height="1">
<a class=nav href="#">Repo Log</a><img src="i/spacer.gif" width="16" height="1"></p>
</td>
<td width="23"><img src="i/a8.jpg"></td>
<td width="104"><img src="i/spacer.gif" width="16" height="1">
<a class=nav href="#">Apt Guide</a><img src="i/spacer.gif" width="16" height="1">
</td>
<td width="23"><img src="i/a8.jpg"></td>
<td width="88"><img src="i/spacer.gif" width="16" height="1">
<a class=nav href="#">Vacation Watches</a><img src="i/spacer.gif" width="16" height="1">
</td>
<td width="24"><img src="i/a8.jpg"></td>
<td width="119"><img src="i/spacer.gif" width="16" height="1">
<a class=nav href="http://pound.ipdinfo.org">Pound Log</a><img src="i/spacer.gif" width="16" height="1">
</td>
<td width="26"><img src="i/a8.jpg"></td>
<td width="114"><img src="i/spacer.gif" width="16" height="1">
<a class=nav href="http://www.ipdinfo.org/pound/users.php">Database Users</a>
<img src="i/spacer.gif" width="16" height="1"></td>
<td width="24"><img src="i/a8.jpg"></td>
<td width="62"><img src="i/spacer.gif" width="16" height="1">
<a class=nav href="#">Admin</a><img src="i/spacer.gif" width="16" height="1">
</td>
<td width="154"><img src="i/spacer.gif"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="background-image: url('i/a19.jpg'); background-repeat: repeat-x"><img src="i/a19.jpg"></td>
</tr>
<tr>
<td style="background-image: url('i/a34.jpg')">
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="background-image: url('i/a28.jpg'); background-repeat: repeat-x">
<tr>
<td><img src="i/spacer.gif" width="9" height="1"></td>
<td valign="top">
<table cellpadding="0" cellspacing="0" border="0" width="166">
<tr>
<td colspan="4"><img src="i/spacer.gif" width="1" height="35"></td>
</tr>
<tr>
<td width="149" align="right">
<a href="#" class="left">FIRST PAGE LINK</a>
</td>
<td><img src="i/spacer.gif" width="11" height="34"></td>
<td><img src="i/a90.jpg"></td>
<td><img src="i/spacer.gif" width="2" height="1"></td>
</tr>
<tr>
<td colspan="4"><img src="i/a37.jpg"></td>
</tr>
<tr>
<td width="149" align="right">
<a href="#" class="left">SECOND PAGE LINK</a>
</td>
<td><img src="i/spacer.gif" width="11" height="34"></td>
<td><img src="i/a90.jpg"></td>
<td><img src="i/spacer.gif" width="2" height="1"></td>
</tr>
<tr>
<td colspan="4"><img src="i/a37.jpg"></td>
</tr>
<tr>
<td width="149" align="right">
<a href="#" class="left">THIRD PAGE LINK</a>
</td>
<td><img src="i/spacer.gif" width="11" height="34"></td>
<td><img src="i/a90.jpg"></td>
<td><img src="i/spacer.gif" width="2" height="1"></td>
</tr>
<tr>
<td colspan="4"><img src="i/a37.jpg"></td>
</tr>
<tr>
<td width="149" align="right">
<a href="#" class="left">FOURTH PAGE LINK</a>
</td>
<td><img src="i/spacer.gif" width="11" height="34"></td>
<td><img src="i/a90.jpg"></td>
<td><img src="i/spacer.gif" width="2" height="1"></td>
</tr>
<tr>
<td colspan="4"><img src="i/a37.jpg"></td>
</tr>
<tr>
<td width="149" align="right">
<a href="#" class="left">FIFTH PAGE LINK</a>
</td>
<td><img src="i/spacer.gif" width="11" height="34"></td>
<td><img src="i/a90.jpg"></td>
<td><img src="i/spacer.gif" width="2" height="1"></td>
</tr>
<tr>
<td colspan="4"><img src="i/a37.jpg"></td>
</tr>
<tr>
<td width="149" align="right">
<a href="#" class="left">SIXTH PAGE LINK</a>
</td>
<td><img src="i/spacer.gif" width="11" height="34"></td>
<td><img src="i/a90.jpg"></td>
<td><img src="i/spacer.gif" width="2" height="1"></td>
</tr>
</table>
</td>
<td><img src="i/spacer.gif" width="9" height="1"></td>
<td style="background-image: url('i/a26.jpg'); background-repeat: repeat-y"><img src="i/a26.jpg"></td>
<td><img src="i/spacer.gif" width="23" height="1"></td>
<td width="100%" valign="top">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td><img src="i/spacer.gif" width="1" height="35"></td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td><img src="i/a33.jpg"></td><td><h2>News</h2></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><img src="i/spacer.gif" width="1" height="22"></td>
</tr>
<tr>
<td>
<?
//include connection script
include('./connect.php');
//specify query to be run
$query="SELECT start,title,news FROM news WHERE (start>=CURDATE() AND end<=CURDATE()) ORDER BY 'start' DESC";
//assign query result to variable
$result=mysql_query($query);
//display data in the users table
if ($result) { //check to see if result returns
//display table header row
echo '<table align="left" cellspacing="0" cellpadding="2" border="0">';
//assign number of rows to variable for loop
$num=mysql_numrows($result);
//begin loop to display data in each row
for ($i=0; $i<$num; $i++){
//assign values to variables within loop to display
$id=mysql_result($result,$i,"id");
$fname=mysql_result($result,$i,"first");
$lname=mysql_result($result,$i,"last");
$rank=mysql_result($result,$i,"rank");
echo "<tr><td align="center"> $id </td>";
echo "<td align="center"> $lname, $fname </td>";
echo "<td align="center">$rank</td></tr>";
}
//print end of table
echo '</table>';
//release memory used by query
mysql_free_result($result);
} else {
//error with getting query
echo '<p>Users could not be displayed</p>';
}
mysql_close();
?>
<br>
<br>
</td>
</tr>
</table>
</td>
<td><img src="i/spacer.gif" width="60" height="1"></td>
</tr>
</table>
<br>
</td>
</tr>
<tr>
<td style="background-image: url('i/a38.jpg'); background-repeat: repeat-x"><img src="i/a38.jpg"></td>
</tr>
<tr>
<td align="center">
Copyright © 2004 <a href="http://www.ipdinfo.org">ipdinfo.org</a>. All rights reserved. Hosting provided by <a href="http://www.xenhosting.com">XenHosting.com</a>
</td>
</tr>
</table>
</body>
</html>
Posted: Wed Oct 13, 2004 5:19 pm
by partiallynothing
Do not use the short PHP tags "<?" and "?>", but use the longer ones "<?php" and "?>".
Posted: Wed Oct 13, 2004 5:21 pm
by bobbyaa
the issue is arising before any variables are called, printed, or anything. it has to do with escaping the quotes basically. i am at a loss though. i have checked and double checked all the quotes for their mates.
Posted: Wed Oct 13, 2004 5:23 pm
by partiallynothing
The file is named index.html, it needs to be named index.php. If a file ends with anything other than .php (and in some cases .php3 and .php4) the php interpreter does not parse it. You must name the file index.php for it to be interpreted.
Posted: Wed Oct 13, 2004 5:26 pm
by kettle_drum
Is php even installed on the server? As its not parsing ANY of it.
Posted: Wed Oct 13, 2004 7:01 pm
by Shendemiar
Make sure you have error reporting on
Posted: Fri Oct 15, 2004 5:55 am
by harrisonad
i found these:
1.) echo '<table align="left" cellspacing="0" cellpadding="2" border="0">';
sometimes error rises from simple string handling: i advise you to practice enclosing the (') between the ("), like this: "this is 'your' string".
2.) $num=mysql_numrows($result);
take care of function spelling. this should be: mysql_num_rows($result)
i also advise you to have an editor with keyword-highlighting feature for you to see those misspelled functions
i hope that helped....
Posted: Fri Oct 15, 2004 5:58 am
by m3mn0n
Help us, help you. Please use Code: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
SOLVED
Posted: Fri Oct 15, 2004 2:23 pm
by bobbyaa
Ok I figured out what the issue was. It was maily the file extension. Thanks for all the help.