我是 PHP/mySQL 的菜鸟,我很喜欢它,但我被困住了……我正在开发我的第一个数据库驱动的网站。我已经创建了数据库,这些表......特别是加载了一个包含内容的表,试图通过 PHP 从中提取数据。如果您通过浏览器实时访问我的网站,则有一个导航系统似乎可以工作,但是它不会从 db 表中加载内容。它只是带有导航系统的空白内容,它更改地址栏中的页面但空白内容。我已经提供了代码以及我试图从中获取数据的数据库中的表的图像拍摄。我从中获取的数据库表称为 vls_pages。它也是图像中的桌子。我希望有人能指出我让它正常运行。谢谢大家
index.php 代码:
<?php
// Load Setup document:
include
('_config/setup.php'); ?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title><?php echo $page_title; ?></title>
<link rel="stylesheet" type="text/css" href="_css/styles.css">
</head>
<body>
<div class="wrap_overall">
<div class="nav_main">
<?php include('_template/nav_main.php'); ?>
</div>
<div class="body_header">
<?php get_page_name($dbc, $pg); ?>
</div>
<div class="content">
<?php get_page_body($dbc, $pg); ?>
</div>
<div class="footer">
<?php include('_template/footer.php'); ?>
</div>
</div>
</body>
</html>
setup.php 代码:
<?php
## Setup Document
// host(or location of the database), username, password, database name
//Variables for connecting to your database.
//These variable values come from your hosting account.
$hostname = "***************";
$username = "***************";
$password = "***************";
//Connecting to your database
$dbc = @mysqli_connect($hostname, $username, $password) OR DIE ("Unsuccessful.");
// Check connection
if (mysqli_connect_errno($dbc))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
include('_functions/snippets.php');
if ($_GET['pgname'] == '') {
$pg = 'home';
}
else {
$pg = $_GET['pgname'];
}
$page_title = get_page_title($dbc, $pg);
?>
片段.php 代码:
<?php
// Snippets; Functions
function get_page_title ($dbc, $pg) {
$query = "SELECT pgtitle FROM vls_pages AND pgstatus = 1 LIMIT 1";
$result = @mysqli_query($dbc, $query);
$page = @mysqli_fetch_assoc($result);
return $page['pgtitle'];
@mysqli_close($dbc);
}
function get_page_name ($dbc, $pg) {
$query = "SELECT pgname FROM vls_pages WHERE pgname = '$pg' AND pgstatus = 1 LIMIT 1";
$result = @mysqli_query($dbc, $query);
$page = @mysqli_fetch_assoc($result);
echo '<h1>'.$page['pgname'].'</h1>';
@mysqli_close($dbc);
}
function get_page_body ($dbc, $pg) {
// the database connection, our query
$query = "SELECT * FROM vls_pages WHERE pgbody = '$pg' AND pgstatus = 1 LIMIT 1";
$result = @mysqli_query($dbc, $query);
$page = @mysqli_fetch_assoc($result);
echo '<div class="content">'.$page['pgbody'].'</div>';
@mysqli_close($dbc);
}
?>