-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent.php
38 lines (33 loc) · 1.06 KB
/
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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "student";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$studentName = $_POST['studentname'];
$studentRegister = $_POST['registernumber'];
$studentContact = $_POST['contactnumber'];
$year = $_POST['year'];
$selectedStream = $_POST['selectedstream'];
$selectedSubjects = $_POST['selectedSubjects'];
$valueadded=false;
$studentInsertQuery = "INSERT INTO details (id, name, reg_num, con_num, year) VALUES ('','$studentName', '$studentRegister', '$studentContact','$year')";
$conn->query($studentInsertQuery);
$studentId = $conn->insert_id;
foreach ($selectedSubjects as $subject) {
$subjects=intval($subject);
$subjectInsertQuery = "INSERT INTO Student_subject (S_id, b_id) VALUES ('$studentId', '$subjects')";
$conn->query($subjectInsertQuery);
$valueadded=true;
}
if ($valueadded) {
echo"DATA ADDED SUCCESSFULLY";
}
else{
echo"DATA ADDED UNSUCCESSFULLY";
}
$conn->close();
?>