1

I am new in php field. i'm using xampp and it's on. and php also activated.

i wrote this code

<!DOCTYPE html>
<html>
<body>

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

</body>
</html>

The output window is empty. I don't know what the error is. Does anyone know the solution?

Evan Fosmark
  • 98,895
  • 36
  • 105
  • 117
Omer Obaid
  • 416
  • 1
  • 6
  • 24

3 Answers3

8

Answer based on comments.

PHP file must be interpreted by web server (in your case - apache with php extension, which is part of XAMPP), which executes PHP code and sends script output/result via http protocol to web browser.

To execute PHP script and show it's result you have to use HTTP, like this: http://localhost/doctrinetest/welcome.php.

c:\xampp\htdocs directory is "served" at http://localhost/ URL.

Opening that file via filesystem (not using apache server) will output blank page, because browser is not supposed to execute PHP. However, that blank page will contain your static HTML part of code.

It looks like, you dont understand how PHP works. You need to read some books about web fundamentals.

Eventually you can visit http://thenewboston.org or http://phpacademy.org - they have very good educational videos.

Kamil
  • 13,363
  • 24
  • 88
  • 183
  • //Opening that file via filesystem (not using apache server) will output blank page, because browser is not supposed to execute PHP. However, that blank page will contain your static HTML part of code.// @Kamil would you please try to answer my question ? https://stackoverflow.com/questions/40453660/create-php-code-not-working-screen-becomes-white-in-xampp?noredirect=1#comment68152934_40453660 – 000 Nov 06 '16 at 20:24
1

It seems that the file is not interpreted as PHP. Make sure that the file has the extension php.

The reason why you don't see the php code is that the tags prevent that, but you should find them in the source code.

You should check that you access the file via http and not directly with the browser. So you should have something like http://localhost/script.php in your address bar.

Also make sure that you have somewhere in your apache config such lines:

#
# PHP-Module setup
#
LoadFile "C:/Program Files (x86)/www/php/php5ts.dll"
LoadModule php5_module "C:/Program Files (x86)/www/php/php5apache2_2.dll"

<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>
rekire
  • 47,260
  • 30
  • 167
  • 264
  • Type of file is php. i'm using window 7 type of file is "PHP file" – Omer Obaid Feb 28 '13 at 18:10
  • @rekire I have problems in xampp white screen . Would you please try to explain? https://stackoverflow.com/questions/40453660/create-php-code-not-working-screen-becomes-white-in-xampp?noredirect=1#comment68152934_40453660 – 000 Nov 06 '16 at 20:26
1

Please google for: How to install XAMPP. When its done, open in browser

http://localhost/

to see if it is working or not.

This is not a real question, before asking something you should learn something.

Wiggler Jtag
  • 669
  • 8
  • 23