-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_student.php
44 lines (38 loc) · 1.4 KB
/
add_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
<?php
include 'connection.php';
$username = mysqli_real_escape_string($connection,$_POST['username']);
$name = mysqli_real_escape_string($connection,$_POST['name']);
$section = $_POST['section'];
$password = mysqli_real_escape_string($connection,$_POST['password']);
$hash = password_hash($password,PASSWORD_DEFAULT);
if (isset($_POST['submit-form'])){
$get_student = "SELECT * FROM users WHERE username ='$username' ";
$result_student = mysqli_query($connection,$get_student);
$count_student = mysqli_num_rows($result_student);
if ($count_student>=1){
$update_student = "UPDATE users SET username='$username', name='$name',
section='$section', password='$hash', active=1 WHERE username='$username' ";
$result_update = mysqli_query($connection,$update_student);
if ($result_update){
header('location:students.php?add=true');
}
else{
echo "An error has occured";
}
}
else{
$add_student = "INSERT INTO users (username,name,section,role,password)
VALUES ('$username', '$name','$section','student','$hash') ";
$result_add = mysqli_query($connection,$add_student);
if ($result_add){
header('location:students.php?add=true');
}
else {
echo "An error has occured";
}
}
}
else{
echo "An error has occured";
}
?>