-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_subject_action.php
47 lines (39 loc) · 1.28 KB
/
create_subject_action.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
<?php
require_once("static/includes/sessions.php");
require_once("static/includes/functions.php");
if(!isset($_SESSION["username"])){
redirect_to('index.php');
}
require_once("static/includes/dbsetup.php");
require_once("static/includes/validation_functions.php");
if(isset($_POST['submit'])){
$menu_name = $_POST["menu_name"];
$position = (int) $_POST["position"];
$visible = (int) $_POST["visible"];
$menu_name = mysqli_real_escape_string($conn,$menu_name);
$required_fields = array("menu_name","position","visible");
validate_presences($required_fields);
$fields_with_max_lengths = array("menu_name" => 30);
validate_max_lengths($fields_with_max_lengths);
if (!empty($errors)){
$_SESSION["errors"] = $errors;
redirect_to("create_subject.php");
}
$query = "INSERT INTO subjects (menu_name,position,visible) VALUES ('{$menu_name}',{$position},{$visible})";
$result = mysqli_query($conn,$query);
if($result){
$_SESSION["message"] = "Subject Creation Successful!";
redirect_to("manage_content.php");
}
else{
$_SESSION["message"] = "Subject Creation Failed!";
redirect_to("create_subject.php");
}
}
else{
redirect_to('create_subject.php');
}
if(isset($conn)){
mysqli_close($conn);
}
?>