-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathca-course-students.php
52 lines (32 loc) · 1.18 KB
/
ca-course-students.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
<?php
error_reporting(0);
session_start();
$host = 'localhost';
$user = 'root';
$password = 'root';
$db = 's_tracker';
$data = mysqli_connect($host,$user,$password,$db);
$s_sql = "SELECT * FROM student_table";
$s_result = mysqli_query($data, $s_sql);
$s_info = mysqli_fetch_assoc($s_result);
$fname = $s_info['fname'];
######################################
$c_sql = "SELECT * FROM courses";
$c_result = mysqli_query($data, $c_sql);
$c_info = mysqli_fetch_assoc($c_result);
$course_id = $c_info['id'];
$cname = $c_info['cname'];
if (isset($_POST['selected']))
{
$selected = $_POST['selected'];
// Step 3: Process each selected record and insert it into the database table
foreach ($selected as $student_id)
{
$query = "INSERT INTO student_course (student_id, fname, course_id, cname) VALUES ('$student_id', '$fname', '$course_id', '$cname')";
mysqli_query($data, $query);
}
// Redirect to a confirmation page
$_SESSION['confirm'] = 'Student Added to Course successfully!';
header("location:ca-course-add.php");
}
?>