-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudents.php
61 lines (46 loc) · 1.66 KB
/
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
53
54
55
56
57
58
59
60
61
<?php
require_once "config.php";
if(isset($_POST['submit'])){
$name = $_POST['name'];
$rollno = $_POST['rollno'];
$locality = $_POST['locality'];
$subjects = $_POST['subject'];
$image = '';
// print_r($subject);exit;
$target_dir = "uploads/";
$target_file = $target_dir . $_FILES["image"]["name"];
$tempname = $_FILES["image"]["tmp_name"];
if (move_uploaded_file($tempname, $target_file)) {
$image = $target_file;
}
$sql = "insert into students( `name` ,`rollno`,`locality`,`image` ) values ('$name','$rollno','$locality','$image')";
mysqli_query($con,$sql);
$student_id = $con->insert_id;
foreach($subjects as $subject){
$sql = "insert into student_subject( `student_id`,`subject_id`) values ('$student_id','$subject')";
mysqli_query($con,$sql);
}
}
$sql = "select * from subjects";
$subjects = mysqli_query($con,$sql);
?>
<center>
<a href="index.php"> Search</a> | <a href="students.php"> Add Student</a> | <a href="subjects.php"> Add Subject</a>
</center>
<h1>Add Students</h1>
<form action="" method="post" enctype="multipart/form-data">
<label>Name: </label><input type="text" name="name"/><br/>
<label>Roll No: </label><input type="number" name="rollno" /><br/>
<label>Locality: </label><input type="text" name="locality" /><br/>
<label>Image: </label><input type="file" name="image"/><br/>
<label>Subjects: </label>
<?php
foreach($subjects as $subject){
?>
<label><input type="checkbox" name="subject[]" value ="<?php echo $subject['id'] ; ?>" /> <?php echo $subject['name'] ; ?></label>
<?php
}
?>
<br/>
<input type="submit" name="submit" />
</form>