IMG dir can't be stored in db but viewed from the same variables used in query IMG dir can't be stored in db but viewed from the same variables used in query ajax ajax

IMG dir can't be stored in db but viewed from the same variables used in query


Are you sure this line isn't throwing a PHP error...

$confirm_upload_db = $$profile_pic_db_upload->rowCount();                     ^^

The $$ (two dollar signs) are how we reference a variable variable; but $profile_pic_db_upload doesn't contain the name of another variable, it's a reference to a PDO statement object.

Another note. The rowCount() function returns the number of rows affected by the UPDATE statement; if the UPDATE statement succeeds, but no actual changes are made to the row (because the values assigned to the columns are the same as what's already stored in the columns), then rowCount() will return 0.

(To change that behavior, to have it return the number of matched rows, you can use PDO::MYSQL_ATTR_FOUND_ROWS).


The problem was fixed using the following query:

$profile_picture_temp = "../images/profile-pictures/" . $thumb_prefix . $new_file_name;$profile_picture_full_temp = "../images/profile-pictures/" . $new_file_name;$session_user = $_SESSION['user_confirm'];$sql = "UPDATE login l SET l.profile_picture_temp = ?, l.profile_picture_full_temp = ? WHERE l.user_session = ?";$stmt = $mysqli->prepare($sql) or die ("Database error<br>" . $sql . "<br><b>Error message:</b> " . $mysqli->error);$stmt->bind_param("sss", $profile_picture_temp, $profile_picture_full_temp, $session_user);$stmt->execute() or die("Something went wrong");$result = $stmt->affected_rows;if($result == 1){    $popup_message = "Profile picture has been uploaded.";    echo $popup_message;}else{    $popup_message = "Profile picture could not be uploaded.";echo $popup_message;}$stmt->free_result();$stmt->close();

I can't identify the problem itself, however, I managed to fix it by adding UPDATE login l. Using alias fixed it somehow.