我正在尝试创建一个显示表中所有记录的数据库连接。问题是在localhost上打开时会显示PHP标记。 表中没有显示记录,因此可能是我的密码不正确。具体来说,它在页面上的localhost中显示:
prepare($sql); $cmd -> execute(); $phpProducts = $cmd->fetchall(); foreach ($phpProduct as $phpProducts) { echo ' '; }
Products Price Description Availability
' . $phpProduct['Products'] . ' ' . $phpProduct['Price'] . ' ' . $phpProduct['Description'] . ' ' . $phpProduct['Availability'] . ' Edit'; $conn = null; require_once('footer.php'); ?>
这是HTML网页的代码:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<link rel="import" href="/shared/breadcrumb.html">
</head>
<body>
<link rel="stylesheet" type="text/css" href="/shared/Style.css">
<h2>Products Catalog</h2>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<ul class="breadcrumb">
<li><a href="#">Home</a></li>
<li><a href="/products/products.html">products</a></li>
<li><a href="/api/API.html">API</a></li>
</ul>
<?php
require_once('header.php');
require_once('db.php');
?>
<?php
$sql = "SELECT * FROM phpProducts";
$cmd = $conn->prepare($sql);
$cmd -> execute();
$phpProducts = $cmd->fetchall();
<table class="table table-striped">
<thead>
<th>Products</th>
<th>Price</th>
<th>Description</th>
<th>Availability</th></thead>
<tbody>
foreach ($phpProducts as $phpProduct) {
echo '
<tr>
<td>' . $phpProduct['Products'] . '</td>
<td>' . $phpProduct['Price'] . '</td>
<td>' . $phpProduct['Description'] . '</td>
<td>' . $phpProduct['Availability'] . '</td>
<td><a href="edit.php?admin_id=' . $Admins['admin_id'] . '"></a></td>
<td><a href="edit.php">Edit</a></td>
</tr>';
}
</tbody>
</table>';
$conn = null;
require_once('footer.php');
?>
</body>
</html>
答案 0 :(得分:0)
PHP标签中有html代码(在表格中)。尝试在HTML之前回显HTML或关闭php标签,然后在html之后再次打开它们。