PHP从数据库中检索记录

Lit*_*ild -1 php

我是PHP和Web开发的新手.到目前为止,我根据我的知识写了一个简单的PHP脚本.这是它的样子,以及HTML:

<!DOCTYPE HTML>
<html>
    <title>Retrieve Users</title>
    <meta charset="utf-8">
    <body>
        <p> List of Subscribers </p>
        <?php
            $query = "select * from subscribers";
            $con = mysqli_connect("localhost","root","","subscribers");
            $result;
            if(mysqli_connect_errno()){
                header("Location: unavailable.html");
                exit;
            }else{
                $result = mysqli_query($con,$query);
            }
        ?>
        <table>
            <?php 
                global $result;
                while( $row = mysqli_fetch_array($result) ){
                    $email = $row['email'];
                    echo "<tr>";
                    echo "<td>"  $email  "</td>";
                    echo "</tr>";
                }
            ?>
        </table>
    </body>
</html>  
Run Code Online (Sandbox Code Playgroud)

但是,我在我的网页上看到了这个:

List of Subscribers

"; echo ""; echo ""; } ?>
" $email "  
Run Code Online (Sandbox Code Playgroud)

我需要在这做什么改变?

Abh*_*rty 5

你忘记了联系

echo "<td>".$email."</td>";
Run Code Online (Sandbox Code Playgroud)

UPDATE

这个问题并不是唯一的问题,文件名有错误的扩展名.

在下列情况下可能会发生这种情况

  1. 没有PHP安装,在这很可能你可能得到php文件下载intead执行.
  2. 文件扩展名错误
  3. 使用php短标记<?在其中php.ini未启用