forked from Reema-murthy/Course-Registration-Prj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_student.php
62 lines (51 loc) · 1.8 KB
/
update_student.php
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
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
// Include database connection
include_once 'db.php';
// Check if the form has been submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the student ID
$student_id = $_POST['studentId'];
// Prepare the SQL statement to update data in the student table
$sql = "UPDATE student SET ";
$updates = array();
// Check if the student name is provided and add it to the update statement
if (isset($_POST['studentId'])) {
$student_name = $_POST['studentName'];
$updates[] = "Student_Name = '$student_name'";
}
// Check if other fields are provided and add them to the update statement
if (isset($_POST['studentPhone'])) {
$student_phone = $_POST['studentPhone'];
$updates[] = "Student_Phone_No = '$student_phone'";
}
// Repeat the process for other fields (student_email, dept_id, etc.)
if (!empty($updates)) {
// Combine all update statements
$update_statement = implode(", ", $updates);
// Complete the SQL statement
$sql .= $update_statement . " WHERE STUDENT_ID = ?";
// Prepare the SQL statement
$stmt = $con->prepare($sql);
// Bind parameters and execute the statement
$stmt->bind_param("i", $student_id);
$stmt->execute();
// Check if the update was successful
if ($stmt->affected_rows > 0) {
// Update successful
echo "Student record updated successfully.";
} else {
// Update failed
echo "Error: Unable to update student record.";
}
// Close the statement
$stmt->close();
} else{
echo "No fields provided for update";
}
} else {
// If the form was not submitted via POST method, return an error message
echo "Error: Form submission method not recognized.";
}
// Close the database connection
$con->close();
?>