PDA

View Full Version : getting php variables to display in an HTML document


mtn_man
January 21st, 2008, 02:31 PM
I seem to be having a problem getting my php vars to show up in my html files.

I know that php is enabled and running on my server as a module of apache and have successfully gotten the famous phpinfo() method to run and display in a browser, but I cannot get even the simplest of output to display when I try to embed some php into an HTML file.

Here is what I have tried:

<?php
echo rand();
?>

yields nothing...

This also is not working:

<?php

$num = 10;
?>

in HTML file:

<p>This is a number from php: <?php echo $num; ?> </p>

I am not sure if I just have my syntax messed up or if I am missing some php/apache config directive or what?

Thanks in advance for any help you might have to offer,

mtn_man

stump138
January 21st, 2008, 02:35 PM
first thing to try would be a phpinfo to see if your php apache is setup correctly. Create a file called "phpinfo.php" and put the following into it.

<?php
phpinfo();
?>

upload it to your webserver and try the url

http://webserver_address/phpinfo.php

If your php/apache setup is good, you should get an information sheet.

fluteflute
January 21st, 2008, 02:37 PM
The first certainly works fine for me.

Are your second two in the same document? If not it will not work.

mtn_man
January 21st, 2008, 02:45 PM
Yes they are in the same document...is there any issue trying to display the results within a div tag?

stump138
January 21st, 2008, 02:58 PM
shouldn't be an issue if you are trying to place it inside of a <div> You can try and see if your php is just working properly
<?php
$num = 10;
echo $num;
?>

mtn_man
January 21st, 2008, 03:03 PM
OK i figured it out...I needed to modify apache's conf file to allow php in html files...

Thanks all for the help!

mtn_man