-
Notifications
You must be signed in to change notification settings - Fork 1
/
coursepage.php
140 lines (111 loc) · 5.04 KB
/
coursepage.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
session_start();
include_once 'dbconnect.php';
$error = false;
//check if form is submitted
if (isset($_POST['signup'])) {
$cname = mysqli_real_escape_string($con, $_POST['cname']);
$cpreq = mysqli_real_escape_string($con, $_POST['cpreq']);
$climit = mysqli_real_escape_string($con, $_POST['climit']);
$descp = mysqli_real_escape_string($con, $_POST['descp']);
//name can contain only alpha characters and space
if (!preg_match("/^[a-zA-Z ]+$/",$cname)) {
$error = true;
$cname_error = "Name must contain only alphabets and space";
}
if(strlen($descp) ==0) {
$error = true;
$descp_error = "You should enter some description";
}
$fid=$_SESSION['usr_id'];
if (!$error)
{
if ($climit!="" and $cpreq!="")
{
if(mysqli_query($con, "INSERT INTO courses(fid,cname,cpreq,climit,descp) VALUES('".$fid."','" . $cname . "', '" . $cpreq . "', '" . $climit. "','".$descp."')")) {
$successmsg = "Successfully Created! <a href='facpage.php'>BACK</a>";
}
}
if ($climit!="" and $cpreq=="")
{
if(mysqli_query($con, "INSERT INTO courses(fid,cname,climit,descp,cpreq) VALUES('".$fid."','" . $cname . "','" . $climit. "','".$descp."','NULL')")) {
$successmsg = "Successfully Registered! <a href='facpage.php'>BACK</a>";}
}
if ($climit=="" and $cpreq!="")
{
if(mysqli_query($con, "INSERT INTO courses(fid,cname,cpreq,descp,climit) VALUES('".$fid."','" . $cname . "', '" . $cpreq . "','".$descp."','NULL')")) {
$successmsg = "Successfully Registered! <a href='facpage.php'>BACK</a>";
}
}
if ($climit=="" and $cpreq=="")
{
if(mysqli_query($con, "INSERT INTO courses(fid,cname,cpreq,descp,climit) VALUES('".$fid."','" . $cname . "','NULL','".$descp."','NULL')")) {
$successmsg = "Successfully Registered! <a href='facpage.php'>BACK</a>";
}
}
}
else {
$errormsg = "Error in submitting please submit the form...Please try again later!";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>ADD COURSES</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport" >
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" />
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- add header -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" >Academic Administration Application</a>
</div>
<!-- menu items -->
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4 well">
<form role="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="signupform">
<fieldset>
<div class="form-group">
<label for="name">Course Name</label>
<input type="text" name="cname" placeholder="Enter Course Name" required value="<?php if($error) echo $cname; ?>" class="form-control" />
<span class="text-danger"><?php if (isset($cname_error)) echo $cname_error; ?></span>
</div>
<div class="form-group">
<label for="name">Prerequisites</label>
<input type="text" name="cpreq" placeholder="Enter the prerequisites for this course" class="form-control" />
</div>
<div class="form-group">
<label for="name">Limit</label>
<input type="number" name="climit" placeholder="Enter the limit of students (Optional)" class="form-control" />
</div>
<div class="form-group">
<label for="name">Course Description</label>
<textarea name="descp" rows = "5" cols = "60" placeholder="Enter the description of this course" required class="form-control" /></textarea>
<span class="text-danger"><?php if (isset($descp_error)) echo $descp_error; ?></span>
</div>
<div class="form-group">
<input type="submit" name="signup" value="Add" class="btn btn-primary" />
</div>
</fieldset>
</form>
<span class="text-success"><?php if (isset($successmsg)) { echo $successmsg; } ?></span>
<span class="text-danger"><?php if (isset($errormsg)) { echo $errormsg; } ?></span>
</div>
</div>
</div>
<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>