-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudents.php
85 lines (67 loc) · 2.17 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
require_once "config.php";
if(isset($_POST['submit'])){
handle_students($con);
}
if(isset($_GET['del'])){
handle_delete_student($con,$_GET['del']);
}
if(isset($_GET['edit'])){
$data = handle_edit_student($con,$_GET['edit']);
}
$subjects = get_subjects($con);
$students = get_students($con);
?>
<?php get_header(); ?>
<h1>Add Students</h1>
<form action="" method="post" enctype="multipart/form-data">
<?php if(isset($_GET['edit'])) { ?>
<input type="hidden" value="<?php echo $data['id']; ?>" name="id" />
<?php } ?>
<label>Name: </label><input type="text" name="name" value="<?php echo $data['name']; ?>"/><br/>
<label>Roll No: </label><input type="number" name="rollno" value="<?php echo $data['rollno']; ?>"/><br/>
<label>Locality: </label><input type="text" name="locality" value="<?php echo $data['locality']; ?>" /><br/>
<label>Image: </label>
<?php if($data['image']) { echo "<img width='50' height='50' src='".$data['image']."' />"; } ?>
<input type="file" name="image"/><br/>
<label>Subjects: </label>
<?php
if($data['id']) $sub = get_subject($con,$data['id']);
foreach($subjects as $subject){
$checked= '';
if( in_array($subject['name'] ,$sub) ){ $checked = " checked=checked "; }
?>
<label><input type="checkbox" <?php echo $checked; ?> name="subject[]" value ="<?php echo $subject['id'] ; ?>" /> <?php echo $subject['name'] ; ?></label>
<?php
}
?>
<br/>
<input type="submit" name="submit" />
</form>
<?php if(mysqli_num_rows($students)){ ?>
<table border="1">
<thead>
<tr>
<th>Photo</th>
<th>Name</th>
<th>Roll No</th>
<th>Locality</th>
<th>Actions</th>
</tr>
</thead>
<?php
while( $student = $students->fetch_row() ){
?>
<tr>
<td><?php echo $student[4]?"<img width='50' height='50' src='$student[4]' />":""; ?></td>
<td><?php echo $student[1]; ?></td>
<td><?php echo $student[2]; ?></td>
<td><?php echo $student[3]; ?></td>
<td><a href="?del=<?php echo $student[0]; ?>">Delete</a> | <a href="?edit=<?php echo $student[0]; ?>">Edit</a></td>
</tr>
<?php
}
?>
</table>
<?php } ?>
<?php get_footer(); ?>