2
 <div id = "info">
 <div class="portlet-body">

  <?php include('mysqlreader.php');?>
 </div>

I want to call php file (mysqlreader.php) in div, mysqlreader.php is in same repository where my actual file is, I tried above mentioned code. But it is not working. what is the proper way to call .php file in html.

Edit: The file's extension I am using for this, is in fact .php

11
  • 5
    You call a PHP file in PHP, not in html. Commented Aug 27, 2014 at 10:37
  • 1
    Did you name your file .html or .php? It has to be named .php unless you've changed your config to run HTML files through PHP. Commented Aug 27, 2014 at 10:39
  • Do specify (next time) as to what your file extension is. Commented Aug 27, 2014 at 10:46
  • my file name has .php extension Commented Aug 27, 2014 at 10:49
  • 1
    @Fred-ii- I was using your answer. I revisited site, and your answer was gone Commented Aug 27, 2014 at 10:59

4 Answers 4

7

You'll have to keep in mind, that in order to run PHP code, you must have a PHP interpreter installed on your server. Second step is that your file actually has a .php extension, otherwise the server will handle it as a simple html file (if its got an .html extension or variant).

Otherwise, your code should look as follows:

<div id = "info">
    <div class="portlet-body">
     <?php
     include('mysqlreader.php');
     ?>
     </div>
 </div>
Sign up to request clarification or add additional context in comments.

Comments

0

To make use of <?php ... ?> your file must be treated as PHP script file first. The simplest approach is to change its name from foo.html to foo.php as .php files (assuming proper server config) should go thru PHP interpreter. Alternatively you can set up your httpd to treat files with other name pattern as PHP as well but the way of doing so depends on httpd used.

1 Comment

foo.htnl => foo.html
0

It's an edit, but that's what I had in here originally.

You had forgotten a </div> which I should have also mentioned.

<div id = "info">

<div class="portlet-body">
<?php

    include('mysqlreader.php');
?>
</div></div>

1 Comment

Sidenote: Downvotes should be kindly retracted, since OP said he had used my answer, but he noticed I had deleted it (because of getting multiple downvotes). Seems like I was right from the get-go. ;)
0

whenever u want to add some php code in html u have to use php structure

<?php 

   //your php code
   //for including file u can use include()function
  include('your file name.php');

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.