Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run php in html

Status
Not open for further replies.

kharddie

Instructor
Feb 7, 2006
23
AU
help-- why cant this php page be processed inside a html document....but when i run it on its own in a php document it works fine.

any ideas?? i have to run it inside a html page in a table ...thank you.



<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table width="464" height="95" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>


<?php



function hapa()
{

ini_set("always_populate_raw_post_data", true);

// Include the database details, and make a connection

include("../tusha_details/tusha_details.php");


$stmt = "SELECT author, body, date from ken_aboutus where state='sa'";

// Get all the posts and necessary information
$result = @mysql_query($stmt, $db);



// Did we get a result?
if (!$result) {

echo "SQL query failed. Please try again.";
exit;

}

// Find the number of rows returned (i.e. the number of posts)
$numRows = @mysql_num_rows($result);

// Were there any rows?
if ($numRows <= 0) {

// No rows were returned, there mustn't be any entries
echo "There are currently no entries in the database.";
exit;

}



$row = mysql_fetch_array($result);
$body=$row['body'];
$author= $row['author'];
$date=$row['date'];

echo $body ;
echo $author ;
echo $date ;



}

$content = hapa();
echo $content;
?>


</td>
</tr>
</table>
</body>
</html>
 
If the page the php code is in has an [green]html[/green] or [green]htm[/green] extension such as mypage.html the server will not know it has PHP code in it, and wont send it to the parser to get run.

You have two optionsÑ

1. change the extension of the file to php. i.e. mypage.[red]php[/red]

OR

2. Cofigure your web server such that it sends htm and html files through the PHP parser. Depending on the server the instructions to configure it properly will vary.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Please tell us what errors are you getting? Is PHP part just displayed and not executed on server? Then you're trying to run a php code block in a file type that is not associated with php on the server. If you're getting errors running the code, then tell us what errors, so that we can help.
 
thanks vacunta will tyr the second option -kharddie
 
The second option, is obviously the harder one.

Is there a particular reason why you don't want or can't change the html extension to php? The html will still work with the PHP extension.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
kharddie,

vacunita has a really point... it really is easier to just name the file .php rather then to tamper with a config file. Nothing bad will happen by changing the .htm or .html to .php ....

imryn
 
the only reason i cant change the html to php is because the out put of the class am using is a *.html .so the browser receives a *.html page .
 
Now you lost me: You are Using a PHP class that outputs an HTML file or outputs HTML code?

If it outputs html code then there is now problem with it running on a PHP page.
If it outputs an HTML file why can;t you change it to ouptut a a file with extension PHP. should not be to hard it you have access to the Class.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Check the other questions this person has asked about PHP and you'll find a pattern.

Lee
 
Ohh, o.k, I understand now where it is you are coming from.

I think in your particular case, it will be best to get html files parsed.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top