每次用戶第一次登錄時,我都會保存一些關於它們的信息。如果用戶已經有條目並且條目已過時,那麼它應該被更新。我的問題是試圖比較用戶和數據庫,看他們是否已經有條目。我成功記錄了用戶的詳細信息,但每次用戶登錄時都會這樣做。下面您可以找到我的代碼。將查詢結果與當前用戶進行比較
$conn = new mysqli('host', 'user', 'password', 'db');
if ($conn->connect_error) {
die("Error; Contact Support!");
}
$stmt = $conn->prepare("select * from users where steamid=? ");
$stmt->bind_param('s', $steamprofile['steamid']);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($res);
$duplicate = mysqli_num_rows($res);
if ($duplicate == 0) {
$stmt1 = $conn->prepare("REPLACE INTO `users` SET `steamid` = ?,`realname` = ?,`username` = ?");
$stmt1->bind_param('sss', $steamprofile['steamid'], $steamprofile['realname'], $steamprofile['personaname']);
$stmt1->execute();
$stmt1->store_result();
$stmt1->bind_result($res1);
if ($res1 === TRUE) {
echo "";
}
$stmt1->close();
$stmt->close();
mysqli_close($conn);
}
'$ duplicate',不管信不信,都不會引發任何錯誤。對於如何查看用戶是否已經擁有數據庫條目,我沒有絲毫的線索,但這是我的悲哀嘗試。 @scaisEdge – Nhabbott
蒸汽id是user_id? ..確保你在$ steamprofile ['steamid'] ..eg中有適當的值:使用var_dump($ steamprofile ['steamid']);然後檢查$ duplicate,例如:var_dump($ duplicate); – scaisEdge