Search code examples
php

Why the browser is commenting out my php code


I am having a weird problem. I have a database (my_db) and I connected to the data base using PDO and successfully tested the connection. Afterward, I created a file with a name 'get_users.php' like the following

<?php
    require '../db/connect.inc.php'; 

    $query = "SELECT * FROM users WHERE role = '0'";
    $result = $handler->query($query);
    while ($row = $result->fetch()) {
        echo $row['first_name'];
    }
?>

I tried to test the query by navigating to the php file that has this query and it echoed all the workers first name.

Finally, In my index.html file. I tried the following

<?php include 'services/get_users.php'; ?> but it did not work. I thought that my path is wrong, however, when I tried to inspect the page I saw my php code like that <!-- <?php include 'services/get_users.php'; -->?>

Why the browser is commenting out my php code. PHP is a server side, I must not be able to see any php tag.

Thank you!!


Solution

  • If your file extension is .html then the PHP interpreter will not read the code. You will want to save your index file as index.php with the .php extension for the interpreter to read it.