-1
此代碼僅顯示空白網頁。它有什麼問題嗎?它應該顯示登錄用戶的總點數。獲取用戶名爲當前用戶名的行的總和
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "randompassword";
$dbname = "transactions";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query = "SELECT sum(points) AS points FROM transaction WHERE username = '".mysqli_real_escape_string($conn,$_SESSION['username'])."'";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
print($row)
?>
你有一個表名爲'transaction'?如果是這樣,我強烈建議你改變它。 – Mike
'transaction'是保留字,所以使用backtique進行轉義。 – Rahul
作爲一般規則,當PHP向您顯示空白頁面時,這是因爲PHP錯誤報告(http://php.net/manual/en/function.error-reporting.php)被設置爲隱藏它。看看你的日誌中遇到的具體PHP錯誤。 –