dongyong3554 2016-05-16 15:28
浏览 6
已采纳

为什么浏览器正在评论我的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!!

  • 写回答

2条回答 默认 最新

  • dongtong7990 2016-05-16 15:34
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失