Ferbla
Ferbla

Reputation: 61

PHP include form trouble

I am having trouble with PHP includes, and I am not entirely sure I am using them correctly. What I have so far is an HTML page that I want to add a search bar to. My PHP code in the HTML page looks like this.

<?php include 'site/tools/search.php'; ?>

The problem I am having is that the search bar is not displaying on the HTML page. I know that the search bar works, because I have browsed to that file location and worked with the actual search bar.

Upvotes: 0

Views: 91

Answers (4)

notquiteamonad
notquiteamonad

Reputation: 1169

Check that your file ends with .php (not .html) and everything should work (your include statement is correct). If this fails, try using an absolute URL.

Upvotes: 1

Branyac
Branyac

Reputation: 479

It may be a problem with the path of the file. If you are using a relative path try adding "./" in the begginning like this: "./site/tools/search.php"

Upvotes: 0

jdp
jdp

Reputation: 366

Use the complete path to the file with your include statement. Like so: <?php include '/home/yourusername/public_html/site/tools/search.php';

Upvotes: 0

JoshMc
JoshMc

Reputation: 739

You cannot use PHP code in HTML documents. Change the extension of your .html file to .php and it should work without affecting anything. This would mean any links to the page would have to be changed accordingly.

Upvotes: 1

Related Questions