我嘗試製作一個簡單的頁面查看計數器。 每次頁面刷新時,數字應增加+1。Php mysql頁面查看計數器
當我在Phpmyadmin中執行代碼時,它一切正常。但在PHP中,計數器返回,但不增加。我做錯了什麼?
<?php
$username = "username";
$password = "password";
$hostname = "hostname";
$dbname = "dbname";
// Create connection
$conn = new mysqli($hostname, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE `Games` SET `Played`= `Played`+1 WHERE 'ID'='3'";
$sql = "SELECT `Played` FROM `Games` WHERE `ID` = 3";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "" . $row[Played]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
這是一個錯誤? ''密碼;'<=缺少引號,另外,這是一個'WHERE'ID''不是數值的列 –
刪除''ID''上的單引號 – Daan
'$ result = mysqli_query($ conn,$ sql)或者死(mysqli_error($ conn));'會發出語法錯誤信號 –