为什么浏览器正在评论我的PHP代码

为什么浏览器正在评论我的PHP代码

问题描述:

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!!

我遇到了一个奇怪的问题。 我有一个数据库(my_db),我使用PDO连接到数据库并成功测试了连接。 之后,我创建了一个名为'get_users.php'的文件,如下所示 p>

 &lt;?php 
 require'../db/connect.inc.php'  ;  
 
 $ query =“SELECT * FROM users WHERE role ='0'”; 
 $ result = $ handler-&gt; query($ query); 
 while($ row = $ result-&gt; fetch(  )){
 echo $ row ['first_name']; 
} 
?&gt; 
  code>  pre> 
 
 

我试图通过导航到php来测试查询 具有此查询的文件,它回显了所有工作人员的名字。 p>

最后,在我的index.html文件中。 我尝试了以下 p>

&lt;?php include'services / get_users.php'; ?&gt; code>但它不起作用。 我认为我的路径是错误的,然而,当我试图检查页面时,我看到我的PHP代码就像&lt;! - &lt;?php include'services / get_users.php'; - &gt;?&gt; code> p>

为什么浏览器会注释掉我的php代码。 PHP是服务器端,我一定不能看到任何php标签。 p>

谢谢!! p> div>

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.

If you want. Html files to be executed as Php then you have edit htpdconfig file Apache where you may add any extension. Note:- For security point of view you should not do so, it may lead to execution of arbitrary php code. You should use. Php extension. You can also rewrite url by which your users will see *.html or *.Nothing ininstead of *.php`. {{ i am on mobile right now, i will update with code soon}}