5 Replies - 798 Views - Last Post: 11 March 2013 - 11:15 PM

#1 hardcoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 06-November 12

Simple PHP code in html not working

Posted 08 March 2013 - 11:46 AM

This seems like really simple php code, but it doesn't seem to work

<!DOCTYPE html>
<html>
<body>

<?php
$x=5;
$y=6;
$z=$x+$y;
?>
<p><?php
echo $z;
?></p>
<p>Hello</p>

</body>
</html>


Is This A Good Question/Topic? 0
  • +

Replies To: Simple PHP code in html not working

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3227
  • View blog
  • Posts: 10,837
  • Joined: 12-December 12

Re: Simple PHP code in html not working

Posted 08 March 2013 - 11:54 AM

What makes you think it doesn't work? Do you receive error messages?

My guess would be that you are not loading the page via a web-server.
Was This Post Helpful? 0
  • +
  • -

#3 hardcoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 06-November 12

Re: Simple PHP code in html not working

Posted 08 March 2013 - 11:59 AM

I'm supposed to get the value of z back, instead it just prints out Hello
Was This Post Helpful? 0
  • +
  • -

#4 Koyume  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 89
  • Joined: 19-February 13

Re: Simple PHP code in html not working

Posted 08 March 2013 - 02:13 PM

View Postandrewsw, on 08 March 2013 - 12:54 PM, said:

What makes you think it doesn't work? Do you receive error messages?

My guess would be that you are not loading the page via a web-server.


That would be my guess to from what he's saying. And make sure your page that you save ends in .php as well as be on a web server with PHP enabled.
Was This Post Helpful? 0
  • +
  • -

#5 josefroyadvincula  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 23-December 12

Re: Simple PHP code in html not working

Posted 11 March 2013 - 09:38 PM

try

echo "$z";
Was This Post Helpful? 0
  • +
  • -

#6 Takk  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 111
  • Joined: 08-March 13

Re: Simple PHP code in html not working

Posted 11 March 2013 - 11:15 PM

View page source should tell you whats going on, however without php installed the page should just display the code as well as hello.

On a second thought, if for some reason your php executable is all screwy for whatever reason, you could get some odd stuff back, possibly check your web server error logs also. Like you say, too simple to not work really.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1