I have a PHP page, where I use mysqli.
I make two prepared statement SQL queries.
My problem is, that at the second query, $conn->prepare($sql)
returns a boolean.
Second query:
UPDATE `users` SET `games` = ? WHERE `id` = ?
Code:
$sql = "SELECT games, username, displayname FROM users WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id);
$result = $stmt->execute();
if ($result === FALSE){
printErrorPage("Something went wrong: " . $conn->error);
die();
}
$stmt->bind_result($json, $username, $displayname);
$stmt->store_result();
if ($stmt->num_rows == 1){
$stmt->fetch();
var_dump($json);
$games = json_decode($json);
var_dump($games);
$games_new = apiUpdate($games);
if ($games_new != $games){
$json_new = json_encode($games_new);
$sql = "UPDATE `users` SET `games` = ? WHERE `id` = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("si", json_encode($games_new), $id);
$result = $stmt->execute();
if ($result !== TRUE){
printErrorPage("Something went wrong: " . $conn->error);
die();
}
}
display($username, $displayname, $games_new);
} else {
if ($stmt->num_rows == 0){
header("Location: http://moger.net/gameboard/");
} else {
//absolute mindfuck
}
die();
}
NOTE: I think that $conn->prepare($sql)
returns FALSE when the SQL syntax is incorrect, but I tested it on this syntax tester (with the prepared statement ?s replaced) and it said it's ok.
EDIT: The question got closed, so I'm going to put the answer here: The UPDATE command wasn't allowed for the user I was using.