I am writing a few webpages and i want to use some php in one of them. The problem is that my php code never displays an ouput even of the simplist form.

I have this very basic code:

<html>
 <head></head>
 <body class="page_bg">
 Hello, today is <?php print("Hello"); ?>.
 </body>
 </html>

It doesnt display hello. I have other more complex webpages that just doesnt seem to do anything.
I am using win 7 and internet explorer 9 (or 10, not sure).
How do I fix this?

Recommended Answers

All 5 Replies

This won't be a problem with your browser at all. It will likely either be the way in which you are running your file or a server configuration problem. Let me ask: Are you running this file on your machine directly by opening your file or are you running it through http://localhost/ ?

I am simply saving my code in a .html file. And then executing the html file.

A number of problems then. You will need to have a web server set up your machine with PHP installed. Your files will need to be in the web root of that web server and finally by default .html files are not executed as PHP.

I'd recommend installing WAMP (If you're on windows), putting your files in "C:\wamp\www" (I think that's the webroot directory), chaning the extension to .php and running the files through putting http://localhost/filename.php in your browser (Or just http://localhost/ if your file is named index.php)

Currently all you are doing is opening your files with your browser which simply tries to render what it finds in there. Server side code has essentially nothing to do with your browser so it will not know what to do with PHP code. You need to get your browser to send requests to your webserver through following the steps above. Your web server will then process the files using PHP and return a response for your browser to render.

Thanks for that, I didnt know I had to use a server to run it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.