Ramya259
Ramya259

Reputation: 43

php not working inside html code in wampserver

Here's the thing.. I have a file named first.php containing the following code:

<html>
    <title>trial</title>
    <head>welcome</head>
    <body>
    <br>
    <?php
    echo "hello world";
    ?>
    </body>
</html>

However when I execute it, the php code is not interpreted. The short open tag also seems to be on. I'm using wampserver. what have I missed?

Upvotes: 1

Views: 8954

Answers (5)

Alaeddine
Alaeddine

Reputation: 1677

The Tag must be inside the Tag

<head> 
   <title>trial</title>
</head>
<body>
 <?php echo "hello world"; ?>
</body>

Upvotes: 0

Ram Ganti
Ram Ganti

Reputation: 21

  1. make sure you place the .php file(s) under a directory say "myfirst" under /wamp/www
  2. make sure the wamp server is online (shows green icon)
  3. Enable short tags click on wamp icon > PHP > PHP Settings > short open tags. Make sure it is checked.
  4. run the code in browser as localhost/myfirst/first.php

hopefully it works

Upvotes: 1

Casey Dwayne
Casey Dwayne

Reputation: 2169

<html>
  <head>    
    <title>trial</title>
  </head>
  <body>
    <?php echo "hello world"; ?>
  </body>
</html>

Try it with the title wrapped inside the head like it should be. The welcome was just floating around in no mans land, may have broken your code. Also, use a doctype tag - < !html> without the space is HTML5.

Update Add this to a blank php file in your localhost folder.

<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>

If you don't get a report back, it's a server config problem.

Also make sure your putting it in htdocs or whatever your "public" folder is.

Upvotes: 0

RiggsFolly
RiggsFolly

Reputation: 94642

Make the changes suggested by @kcdwayne.

Now run the code from your browser, DONT doubleclick on your php file from explorer, it has to run through a browser.

Upvotes: 0

Jose Areas
Jose Areas

Reputation: 719

It seems your server is misconfigured. Your apache server must recognize .php files as a php application and evaluate the code.

AddHandler application/x-httpd-php .php

See if you find the line above in your http.conf file.

Upvotes: 2

Related Questions