Page 1 of 1

Displaying PHP in HTML - Help!

Posted: Wed Dec 23, 2009 12:52 am
by jpcoombs
I am trying to display information from an SQL database onto an HTML page. The goal is to display the Title and Article inside of a white space on an HTML page.

I copy/paste the code into an HTML document and it doesn't seem to work. How do I get the Title and Article from the following code to display properly?

Code: Select all

<?php
require_once('includes/DbConnector.php');
$connector = new DbConnector();
$result = $connector->query('SELECT title,thearticle FROM cmsarticles WHERE ID = 1');
$row = $connector->fetchArray($result);
?>
 
<?php echo $row['title'];?>
 
<?php echo $row['thearticle'];?>

Re: Displaying PHP in HTML - Help!

Posted: Wed Dec 23, 2009 1:33 am
by requinix
jpcoombs wrote:How do I get the Title and Article from the following code to display properly?
Depends what "properly" means, and how that's different from what it's doing now.

Re: Displaying PHP in HTML - Help!

Posted: Wed Dec 23, 2009 12:01 pm
by jpcoombs
Well nothing is happening when I paste that exact code into HTML. It should be taking two data points, title and thearticle, and displaying them. But all I get is the a part of the code displayed on the HTML - as if its not reading the <?php ?>. Here is the result when its pasted verbatum on a website:

query('SELECT title,thearticle FROM cmsarticles WHERE ID = 1'); ?>

And thats it.

Re: Displaying PHP in HTML - Help!

Posted: Wed Dec 23, 2009 12:06 pm
by jpcoombs

Re: Displaying PHP in HTML - Help!

Posted: Wed Dec 23, 2009 12:31 pm
by manohoo
Let's take a look at the contents of $row. Please do this and post the result:

echo "<pre>";
var_dump($row);

Re: Displaying PHP in HTML - Help!

Posted: Wed Dec 23, 2009 12:56 pm
by jpcoombs

Re: Displaying PHP in HTML - Help!

Posted: Wed Dec 23, 2009 1:24 pm
by manohoo
I noticed a fundamental flaw in your code.

You can embed html in a php file. Example:
file: index.php

Code: Select all

 
<html>
<head>
</head>
<body>
<?php echo "hello there!"; ?>
</body>
</html>
 
the above will output:
hello there!

But, you can't embed PHP in an html file:
file: index.html

Code: Select all

 
<html>
<head>
</head>
<body>
<?php echo "hello there!"; ?>
</body>
</html>
 
The above will not output anything.

Re: Displaying PHP in HTML - Help!

Posted: Wed Dec 23, 2009 1:31 pm
by jpcoombs
Is there a solution? My goal is to embed updates into HTML so that clients can make changes to only single areas of the site through PHP - then the HTML is updated.

Re: Displaying PHP in HTML - Help!

Posted: Wed Dec 23, 2009 1:48 pm
by manohoo
For starters you need to use only PHP files.

zip your files and send to my email (manoloDOTwebmaster@gmailDOTcom), I'll take a closer look. And please try to explain as well as you can what you are trying to accomplish.

Re: Displaying PHP in HTML - Help!

Posted: Wed Dec 23, 2009 2:15 pm
by jpcoombs
Manohoo - thanks for all your feedback. It got me thinking - im just gonna develop this whole site using PHP and build it right rather than jury rigging existing code. Good challenge anyway. But you have been a big help - thanks!