Skip to content

Commit 44337ea

Browse files
committed
Removed error reporting settings, updated AJAX URL, and added error handling with logging in edit-profile.php; added prepare statement error check in profile_functions.php
1 parent 73e28e5 commit 44337ea

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

dashboard/edit-profile.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<?php
2-
ini_set('display_errors', 1);
3-
ini_set('display_startup_errors', 1);
4-
error_reporting(E_ALL);
52
session_start();
63

74
$page_title = "Edit Profile";
@@ -196,7 +193,7 @@
196193
const formData = new FormData(this);
197194

198195
$.ajax({
199-
url: './edit-profile',
196+
url: '../includes/user/profile-edit',
200197
type: 'POST',
201198
data: formData,
202199
processData: false,
@@ -218,12 +215,13 @@
218215
});
219216
}
220217
},
221-
error: function() {
218+
error: function(xhr, status, error) {
222219
Swal.fire({
223220
title: 'Error!',
224-
text: 'An error occurred while updating your profile.',
221+
text: 'An error occurred while updating your profile: ' + error,
225222
icon: 'error'
226223
});
224+
console.error(xhr.responseText); // Log server response for debugging
227225
}
228226
});
229227
}

includes/user/profile-edit.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
session_start();
3+
include '../../config/config.php';
4+
include '../get_universities.php';
5+
include './profile_functions.php';
6+
7+
8+
$user_id = $_SESSION['user_id'];
9+
$bank_list = getBanks();
10+
$levels = range(100, 900, 100);
11+
12+
// Get user's current data
13+
$user_data = getUserData($user_id);
14+
15+
// Handle form submission via AJAX
16+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
17+
header('Content-Type: application/json');
18+
$response = array('success' => false, 'message' => '');
19+
20+
// Validate unique fields
21+
if (!isFieldUnique('username', $_POST['username'], $user_id)) {
22+
$response['message'] = 'Username already exists!';
23+
echo json_encode($response);
24+
exit;
25+
}
26+
if (!isFieldUnique('email', $_POST['email'], $user_id)) {
27+
$response['message'] = 'Email already exists!';
28+
echo json_encode($response);
29+
exit;
30+
}
31+
if (!isFieldUnique('phone', $_POST['phone'], $user_id)) {
32+
$response['message'] = 'Phone number already exists!';
33+
echo json_encode($response);
34+
exit;
35+
}
36+
37+
// Update profile
38+
$result = updateUserProfile($user_id, $_POST);
39+
40+
if ($result) {
41+
$response['success'] = true;
42+
$response['message'] = 'Profile updated successfully!';
43+
} else {
44+
$response['message'] = 'Error updating profile!';
45+
}
46+
47+
echo json_encode($response);
48+
exit;
49+
}

includes/user/profile_functions.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ function updateUserProfile($user_id, $data) {
157157
WHERE id = ?";
158158

159159
$stmt = $conn->prepare($query);
160+
161+
// Check if prepare failed
162+
if (!$stmt) {
163+
throw new Exception("Preparation failed: " . $conn->error);
164+
}
165+
160166
$stmt->bind_param("ssssssssisssi",
161167
$data['fullname'],
162168
$data['username'],

0 commit comments

Comments
 (0)