我想在我的頁面中回顯sql數據庫記錄,我正在使用此代碼。當我運行它時不顯示數據庫的結果。我在數據庫中有符合條件的記錄。我是新的PHP和SQL,所以請告訴我哪裏有錯誤。無法顯示數據庫記錄
session_start();
if (!isset($_SESSION['name'])) {
header('Location:vhod.php');
exit;
}
$pageTitle = 'СЪОБЩЕНИЯ';
include 'includes/header.html';
$email = $_SESSION['email'];
$name = $_SESSION['name'];
include 'php/db_connect.php';
$msgs = '';
$query = 'SELECT `timestamp`, `to`, `sender`, `subject`, `msg` FROM msg WHERE `to`="$name"';
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$msgs = "ДАТА: " . $row["timestamp"] . " >> От: " . $row["sender"] . " >> Тема: " . $row["subj"] . " >> Съобщение: " . $row["msg"] . "<br>";
}
} else {
$msgs = "Нямате съобщения :(";
}
這些諮詢以下鏈接http://php.net/manual/en/mysqli.error.php和http://php.net/manual/en/function.error-reporting.php 和應用這對你的代碼。 –
btw,你在查詢中選擇了'subject'列,但是在'$ row [「subj」]'中使用'subj',MySQL會拋出一些關於它的東西,就像在「不存在的列」中一樣。 –