I am stumped. I just need someone to look over my code and give me ideas as to why the connection isn't working. It works for all other update functions I have (similar code/copy pasted), just not this one.
I must also add that it runs and updates the database. My issue is with getting the results at the end. I traced back the error to the connection and it just doesn't make any sense anymore.
/**
* Update Avatar Function
*/
function updateAvatar($conn, $username, $avatar) {
// setup a query
$sql = "UPDATE users SET avatar = ? WHERE username = ?;";
// prepare a statement to send a sanitized query
$stmt = mysqli_stmt_init($conn);
// check for a fail in case the query is faulty
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: ../admin/account.php?error=stmtfailed");
exit();
}
// bind our data to the statement and execute
mysqli_stmt_bind_param($stmt, "ss", $avatar, $username);
mysqli_stmt_execute($stmt);
// save the avatar
$avatar = json_decode($avatar, true);
move_uploaded_file($avatar["tmp_name"][0], '../assets/images/uploads/' . $avatar["name"][0]);
// grab the returned data
$resultData = mysqli_stmt_get_result($stmt);
// try to grab the row and return it
if (!$row = mysqli_fetch_assoc($resultData)) {
return $row;
}
// close the statement
mysqli_stmt_close($stmt);
// send the user to the account page with a success message
header("location: ../admin/account.php?success=update");
}