此代码只显示一个空白网页。它有什么问题吗?它应该显示登录用户的总点数。
<?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)
?>
答案 0 :(得分:0)
您应该像这样启用error_reporting
error_reporting(E_ALL);
ini_set("display_errors", 1);
transaction
是mysql中的关键字。所以请使用返回tick(`)。
您可以使用以下方法来避免使用直接替换值,而不是使用直接替换值。
使用MySQLi(用于MySQL):
$stmt = $dbConnection->prepare('SELECT * FROM employees WHERE name = ?'); $stmt->bind_param('s', $name); $stmt->execute(); $result = $stmt->get_result(); while ($row = $result->fetch_assoc()) { // do something with $row }