HTML/PHP Include - [Help Needed]
Good day all, please how do i include a dynamic page(php) into an html page?
i did a part development for a website, and most of the pages are in html(but those part i did, i did in php).
meanwhile, there are some included file in my php that has to be global on all pages on the website.
so how do i incorporate these php files into the existing html files because renaming these html files is not an option.
i have tried the SSI method:
Code:
<!--#include file="myfile.php" -->
it did not work(even after renaming the file that contains the above code to a .shtml)
i also try including the PHP file using the hTML script tag:
Code:
<script src="myfile.php"></script>
can anybody please help?
Thanks
Re: HTML/PHP Include - [Help Needed]
you can't ... not directly at any rate... you could use AJAX to do a GET on the php files (which would cause it to run on the server, which is what you need, and return the results). Once you have the results, you can use the DOM and javascript to insert the data where you need it to.
Why can't the HTML files be renamed?
-tgh
Re: HTML/PHP Include - [Help Needed]
With xhtml the php needs to be in the same file as the html in order to work:
Code:
<p align="center"><strong><font size="7" face="Courier New, Courier, monospace">Welcome to Bazaar Ceramics</font></strong></p>
<p align="center">Please select one of the options below: <br />
</p>
<table width="650" border="1" cellspacing="0" cellpadding="0" align="center">
<tr>
<td><div align="center"><strong><a href="getCustomerDetails.php">Customer Registration</a> </strong></div></td>
<td><div align="center"><strong>Display Catalogue </strong></div></td>
<td><div align="center"><strong>Account Order </strong></div></td>
<td><div align="center"><strong>Shopping Cart </strong></div></td>
<td><div align="center"><strong><a href="getProductDetails.php">Product Entry</a> </strong></div></td>
</tr>
</table>
<hr>
<?php
/*check if form fields are blank. If they are, let the customer know and
provide a link to return to the original customer details form*/
if ($_POST["productname"] ==""){
echo "you need to enter the product name";
echo "<br><a href='getProductDetails.php'>Return to form</a>";
} elseif ($_POST["productdesc"] =="") {
echo "you need to enter the product description.";
echo "<br><a href='getProductDetails.php'>Return to form</a>";
}elseif($_POST["colour"] == ""){
echo "you need to enter a colour";
echo "<br><a href='getProductDetails.php'>Return to form</a>";
}elseif($_POST["price"] == ""){
echo "you need to enter a price";
echo "<br><a href='getProductDetails.php'>Return to form</a>";
}elseif($_POST["imagepath"] == ""){
echo "you need to enter a correct image path";
echo "<br><a href='getProductDetails.php'>Return to form</a>";
}else {
$conn = @mysql_connect("localhost", "root", "");
if (!$conn) {
die("Connection failed: " .mysql_error());
}
mysql_select_db("Bazaar Ceramics", $conn);
$query = "INSERT INTO products (productname, productdesc, colour, price, imagepath)
VALUES ('$_POST[productname]', '$_POST[productdesc]', '$_POST[colour]', '$_POST[price]', '$_POST[imagepath]')";
if (mysql_query($query, $conn)){
echo ("<br><b>The following product has been added to the database: </b>" .$_POST[productname]);
echo "<br><br><a href=getProductDetails.php>Add another product?</a>";
}else {
die(mysql_error());
}
}
?>
However, it is possible to link to the php page like so:
Code:
<a href="getCustomerDetails.php">Customer Registration</a>
Re: HTML/PHP Include - [Help Needed]
thanks all,
@Nightwalker83
i do know how to link to a page.
- - - - - - - - - - - - - - - - - - - -
Maybe i'll have to go with the option of parsing .html as .php using htaccess.
then their web guys will have to inlude the php file using the php include() function.
Thanks
Re: HTML/PHP Include - [Help Needed]
Quote:
Originally Posted by
Nightwalker83
With xhtml the php needs to be in the same file as the html in order to work:
Code:
<p align="center"><strong><font size="7" face="Courier New, Courier, monospace">Welcome to Bazaar Ceramics</font></strong></p>
<p align="center">Please select one of the options below: <br />
</p>
<table width="650" border="1" cellspacing="0" cellpadding="0" align="center">
<tr>
<td><div align="center"><strong><a href="getCustomerDetails.php">Customer Registration</a> </strong></div></td>
<td><div align="center"><strong>Display Catalogue </strong></div></td>
<td><div align="center"><strong>Account Order </strong></div></td>
<td><div align="center"><strong>Shopping Cart </strong></div></td>
<td><div align="center"><strong><a href="getProductDetails.php">Product Entry</a> </strong></div></td>
</tr>
</table>
<hr>
<?php
/*check if form fields are blank. If they are, let the customer know and
provide a link to return to the original customer details form*/
if ($_POST["productname"] ==""){
echo "you need to enter the product name";
echo "<br><a href='getProductDetails.php'>Return to form</a>";
} elseif ($_POST["productdesc"] =="") {
echo "you need to enter the product description.";
echo "<br><a href='getProductDetails.php'>Return to form</a>";
}elseif($_POST["colour"] == ""){
echo "you need to enter a colour";
echo "<br><a href='getProductDetails.php'>Return to form</a>";
}elseif($_POST["price"] == ""){
echo "you need to enter a price";
echo "<br><a href='getProductDetails.php'>Return to form</a>";
}elseif($_POST["imagepath"] == ""){
echo "you need to enter a correct image path";
echo "<br><a href='getProductDetails.php'>Return to form</a>";
}else {
$conn = @mysql_connect("localhost", "root", "");
if (!$conn) {
die("Connection failed: " .mysql_error());
}
mysql_select_db("Bazaar Ceramics", $conn);
$query = "INSERT INTO products (productname, productdesc, colour, price, imagepath)
VALUES ('$_POST[productname]', '$_POST[productdesc]', '$_POST[colour]', '$_POST[price]', '$_POST[imagepath]')";
if (mysql_query($query, $conn)){
echo ("<br><b>The following product has been added to the database: </b>" .$_POST[productname]);
echo "<br><br><a href=getProductDetails.php>Add another product?</a>";
}else {
die(mysql_error());
}
}
?>
However, it is possible to link to the php page like so:
Code:
<a href="getCustomerDetails.php">Customer Registration</a>
Really? You sure you want to stick to that statement? Because I've built sites with my PHP scattered across several files. Even still... unless the file is told to be processed as a PHP file, simply including the php script markers doesn't make it go.... What you'll get instead is the PHP code rendered to the client.
modpluz - I'm still unclear on why the files can't be renamed to PHP files?
-tg
Re: HTML/PHP Include - [Help Needed]
Quote:
Originally Posted by
techgnome
Really? You sure you want to stick to that statement?
You misunderstood what I meant! I was saying that you must put the php in with xhtml not that it had to be in the same page. Sorry, for the confusion!
Re: HTML/PHP Include - [Help Needed]
Quote:
Originally Posted by techgnome
modpluz - I'm still unclear on why the files can't be renamed to PHP files?
thats because they have hundreds of html files