Hi. I'm pretty new to PHP. I'm using PHP 5, MySQL Server 5.0 and Apache 1.3.34 (as the book about PHP I have advised Apache 2 is not entirely stable with PHP).

Even the simplest PHP code doesn't seem to work for me. I called a file test.php and used the following code:

<html>
<body>

<?php
echo "test";
?>

</body>
<html>

...and just get a blank page. I can forget trying to retrieve or insert MySQL records if that doesn't even work.

Am I going wrong is some basic, obvious way with PHP? Or is there likely to be something wrong with my install of PHP or Apache?

Many thanks....

    Is your Apache webserver running, do you get the welcome page when you type http://127.0.0.1/ into your browser address bar?

    Is the test.php in your htdocs folder (or if you specified a different folder name at installation, in that folder)

    Are you calling the page through your browser from localhost like : http://127.0.0.1/test.php?

    Did you carefully follow the installation instructions?

      Hi try this put at the top of your page
      $test = "Hello World";
      Then inside your html code place this
      <?php echo $test; ?>

      You should get printed Hello World in your browser 🙂

      P.S im quite sure this will work unless its a setup problem no offence intended 😃

      Regards Pinky 🙂

        Not only what he said but if you type

        echo "test";

        your browser will only write the word 'test' in the page.

        If you want to call the file you should type:

        include 'test.php';

        that is what will call the file.

          If I go to http://localhost/ I get the screen confirming Apache is running, and if I go to http://localhost/htdocs/test.php I get the PHP information readout.

          However, the problem is that any PHP file I write myself does not seem to work properly. I may have confused the matter by calling my file test.php. It's not in the Localhost folder, it's stored on my desktop. I open the browser then drag in the file, and the browser simply displays a blank screen. Any standard HTML I input renders as normal, but the PHP script is either ignored, or partially shown in the browser!

          Hi try this put at the top of your page
          $test = "Hello World";
          Then inside your html code place this
          <?php echo $test; ?>

          Yeah, that doesn't work either, tried similar already.

            Thrikodithanam wrote:

            If I go to http://localhost/
            However, the problem is that any PHP file I write myself does not seem to work properly. I may have confused the matter by calling my file test.php.

            Yes don't have two files with the same name.

            It's not in the Localhost folder, it's stored on my desktop. I open the browser then drag in the file, and the browser simply displays a blank screen. Any standard HTML I input renders as normal, but the PHP script is either ignored, or partially shown in the browser!.

            Well it won't work if you don't run it from the webserver, running a file from your desktop is NOT the same as running it through the webserver. If your htdocs/test.php shows the php info then your installation is fine.

            But you HAVE to run the files from htdocs and call them the same way as you would call any other web page through the browser.

              Right. OK, I will try running a file from inside Htdocs when I get home, see if that solves it!

              So any PHP file I want to run on my machine needs to be inside the Htdocs folder? I shall have to reorgansie my filing system....

                Yes as well as it being named with a .php extension in order for the PHP parser to read the script.

                  OK! I moved the file into the localhost folder (or rather, changed what Apache thought of as the localhost folder) and it works now! Gleeeeeeee! 🙂

                    Write a Reply...