} else { $sql = "update users set first_name=:fname,last_name=:lname,city=:city,country=:country,gender=:gender where id=:id"; } $sth = $conn->prepare($sql); $sth->bindValue("fname", $first_name); $sth->bindValue("lname", $last_name); $sth->bindValue('city', $city); $sth->bindValue('country', $country); $sth->bindValue('gender', $gender); $sth->bindValue('id', $uid); if ($image_path) { $sth->bindValue('image', $image_path); } try { $sth->execute(); $success = 1; $msg = "User info updated"; $profile = DataClass::get_profile_by_id($uid); $data = $profile ? $profile : []; } catch (Exception $e) { //echo $e->getMessage(); } } // +-----------------------------------+ // + STEP 4: send json data + // +-----------------------------------+ if ($success == "1") { echo json_encode(array("success" => $success, "msg" => $msg, "data" => $data)); } else { echo json_encode(array("success" => $success, "msg" => $msg)); }