Ed Fordham
Ed Fordham

Reputation: 31

PHP file is printing everything after echo command

I'm trying to build my first website. I have a domain name and am building it on my laptop before uploading it to my host. The website is mostly focused around searching a database of family tree information.

I have created a basic HTML file which seems to be working ok. I have a search button linked to a PHP file. Ideally when someone used the button without putting in parameters it should reply with an error message that says "search term is missing" but instead it shows all the code for the PHP file. I've never done anything like this before so am more than a little confused.

Upvotes: 3

Views: 3225

Answers (3)

Attila
Attila

Reputation: 3406

If you would like to test your PHP code running on your own machine you must set up some things first. You need you own web server and PHP interpreter installed. You can do this easily by installing a package like XAMPP.

This comes with a graphical install package and includes everything you need to host a PHP file.

XAMPP's website

After you have installed this you are going to have a special directory, "htdocs". By default: c:\xampp\htdocs

If you add some files here it is going to be published on your webserver.

For example if you create an index.php it is going to be located on:

http://localhost

more precisely:

http://localhost/index.php

In PHP files you must include special character sequences telling the interpreter that there is PHP code.

<?PHP
// your PHP code goes here
?>

First you should test your server by having a very simple file. eq.:

<?PHP
  echo "Test";
?>

IF this works fine you can go for some further tutorials to dig deeper in PHP. (It should only output the Test string - this is the result of running of the PHP code block)

PHP tutorial

Have fun!

Upvotes: 1

aumbadgah
aumbadgah

Reputation: 70

Your browser will not understand php by itself, on a given web server there's a number of layers for compiling PHP etc. Try XAMPP, you'll have it up and running in no time and you can see your PHP at work by simply looking up localhost with your browser.

Upvotes: 2

Mostafa Berg
Mostafa Berg

Reputation: 3239

Welcome to the web development world !;)

the php file must have a .php extensions, and should begin with <?php and end with ?>

you probably forgot one of those :)

Upvotes: 2

Related Questions