-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddstudent.php
More file actions
34 lines (32 loc) · 1.31 KB
/
Copy pathaddstudent.php
File metadata and controls
34 lines (32 loc) · 1.31 KB
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
<?php
include 'config.php';
$firstname=$_POST["studentFirstName"];
$lastname=$_POST["studentLastName"];
$email=$_POST["studentEmail"];
$age=$_POST["studentAge"];
$num=$_POST["studentNum"];
$mat=$_POST["studentMatricule"];
$group_id = $_POST["studentgroupe"];
$check_sql1 = "SELECT * FROM students WHERE matricule = '$mat' ";
$check_sql2 = "SELECT * FROM accounts WHERE email = '$email' ";
$check_result1 = mysqli_query($conn, $check_sql1);
$check_result2 = mysqli_query($conn, $check_sql2);
if (mysqli_num_rows($check_result1) > 0) {
echo "The matricule already exists.Try another one.";
exit;
}
if(mysqli_num_rows($check_result2)>0){
echo "The email already exists. try another one.";
exit;
}
$sql1 = "INSERT INTO students ( firstname, lastname, email, num, matricule, age,group_id ) VALUES ('$firstname','$lastname','$email','$num','$mat','$age','$group_id')";
$password = $firstname . $mat;
$password = password_hash($password, PASSWORD_DEFAULT);
$sql2 = "INSERT INTO accounts ( email , password, role ,matricule ) VALUES ('$email', '$password','student','$mat')";
if(($conn->query($sql1)===TRUE )&&($conn->query($sql2)===TRUE )){
header('Location: students.php');
die();
} else{
echo "Error: " . $sql1 . "<br>" . $conn->error;echo "Error: " . $sql2 . "<br>" . $conn->error;
}
?>