Results 1 to 7 of 7

Thread: HTML/PHP Include - [Help Needed]

  1. #1

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Question 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
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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>
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  4. #4

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    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
    Last edited by modpluz; Jun 23rd, 2009 at 12:06 PM.
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: HTML/PHP Include - [Help Needed]

    Quote Originally Posted by Nightwalker83 View Post
    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: HTML/PHP Include - [Help Needed]

    Quote Originally Posted by techgnome View Post
    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!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  7. #7

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    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
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width