我是PHP/mySQL的noob,我很享受它,但我被卡住了......我正在開發我的第一個數據庫驅動的網站。我已經創建了數據庫,這些表...特別加載了一個表與內容,試圖通過PHP從數據中提取數據。如果您通過瀏覽器直接訪問我的網站,那麼似乎有一個導航系統可以工作,但它不會從數據庫表中加載內容。這只是空白的內容與導航系統,更改地址欄中的頁面,但空白的內容。我已經提供了代碼以及數據庫中表格的圖像鏡像,我正在嘗試從中獲取數據。我得到的數據庫表叫做vls_pages。這也是圖片中的表格。我希望有人能指出我要讓這個功能正常工作。謝謝大家我的第一個PHP/MySQL數據庫,沒有輸出到網頁?
的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 CODE:
<?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);
?>
snippets.php CODE:
<?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);
}
?>
你很容易受到[SQL注入攻擊(http://bobby-tables.com)。在你瞭解這些代碼之前,停止處理這些代碼,以及如何避免它們。作爲一般性提示,**從不**使用'@'錯誤抑制操作符,特別是在您學習時。這是將你的手指伸入耳朵的編碼等同於「lalalalalal聽不到你alalalalalal」。 –
爲什麼所有的'@'? – Barmar
一方面做'$查詢=「選擇pgtitle從vls_pages WHERE pgstatus = 1 LIMIT 1」;'不是'AND' –