-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate_prof.php
More file actions
49 lines (45 loc) · 1.66 KB
/
update_prof.php
File metadata and controls
49 lines (45 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
session_start();
if (isset($_SESSION['email'])) {
require 'partials/conn.php';
header("Location: logdisp.php");
$id = $_POST['id'];
$name = $_POST['name'];
$dob = $_POST['dob'];
$contact = $_POST['contact'];
$address = $_POST['address'];
$email = $_POST['email'];
$gender = $_POST['gender'];
// Handle file upload
$file = $_FILES['file']['name'];
$targetDir = __DIR__ . "/uploads/";
$fileName = basename($_FILES["file"]["name"]);
$targetFilePath = $targetDir . $fileName;
$fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION);
$allowTypes = array('jpg', 'png', 'jpeg', 'gif', 'pdf');
if (!empty($file) && in_array($fileType, $allowTypes)) {
if (move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)) {
$sql = "UPDATE student_intern SET name=?, dob=?, contact=?, address=?, email=?, gender=?, file=? WHERE id=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("sssssssi", $name, $dob, $contact, $address, $email, $gender, $fileName, $id);
} else {
echo "Sorry, there was an error uploading your file.";
exit();
}
} else {
$sql = "UPDATE student_intern SET name=?, dob=?, contact=?, address=?, email=?, gender=? WHERE id=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssssssi", $name, $dob, $contact, $address, $email, $gender, $id);
}
if ($stmt->execute()) {
echo "Profile updated successfully.";
} else {
echo "Error updating profile: " . $stmt->error;
}
$stmt->close();
$conn->close();
} else {
header("Location: login.php");
exit();
}
?>