【发布时间】:2021-05-23 06:08:47
【问题描述】:
我试图将数据库中的数据显示到 html 表中。但是当我运行它时,它不会显示数据库数据。它只是像这样显示,'.$res['name'].'。我认为我犯了一个愚蠢的错误,但无法发现。
编辑:对不起,这是一个愚蠢的错误。我已将文件保存在 .html 扩展名中,我将其保存在 .php 中,现在它工作正常。感谢大家。 我的 view.php 文件:
<?php
include_once ("config.php");
$result = mysqli_query($mysqli,"SELECT* FROM `testing` ORDER BY `id` DES");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<table border="1">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
<?php
while($res=mysqli_fetch_array($result)){
echo '<tr>';
echo '<td>'.$res['name'].'</td>'; // here it just shows up like '.$res['name'].'</td>' , instead of showing data.
echo '<td>'.$res['email'].'</td>';
echo '<td>'.$res['phone'].'</td>';
echo '</tr>';
}
?>
</table>
</body>
</html>
我的 config.php 文件:
<?php
$dbhost = "localhost";
$dbname = "datatest";
$dbuser = "root";
$dbpwd = "";
$mysqli = mysqli_connect($dbhost,$dbuser,$dbpwd,$dbname);
?>
【问题讨论】:
-
如果您在屏幕上看到这样的 PHP 代码,我想知道 PHP 是否没有安装,或者您的网络服务器中没有正确配置,或者您是否没有通过正确的方式访问页面HTTP
-
一旦你修复了这个问题,你应该注意你的查询中的错误,如下面 user27976 的回答中提到的