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 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了