problem with php code in html file
-
I made an html file containing php simple code, but nothing appears on monitor!!
my html file:
<!DOCTYPE html>
<html>
<body>
<?php
$foo = “foobar”;
$bar = “barbaz”;
echo “foo is $foo”; // foo is foobar
?>
</body>
</html>
I’ m trying to solve a bigger problem (I’ m trying to handle a db through html, css, php, xampp) when I found out the above.
PLEASE HELP!! -
what do you mean by saying nothing appears on monitor?
You don’t see the code you posted within notepad++?
You don’t see the html page if you open the page?
If so, how do you call it, meaning what is used to call the php code?Cheers
Claudia -
When I open the html file with my browser (Chrome, Edge, Mozilla), nothing appears on monitor. When I put text outside of the php code (in the html file written via notepad++), this text has no problem appearing on my monitor when I refresh the html file. example:
<!DOCTYPE html>
<html>
<body>
I can read
<?php
$foo = “foobar”;
$bar = “barbaz”;
echo “foo is $foo”; // foo is foobar
?>
this but not “foo is foobar” which should appear
</body>
</html> -
you need to understand that the browser doesn’t execute your php code, in fact the browser do only
understand html. It’s the webserver which executes the php code and makes proper html out of it,
which then is sent to the browser.Cheers
Claudia