-
Notifications
You must be signed in to change notification settings - Fork 0
/
add.php
98 lines (73 loc) · 2.47 KB
/
add.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
<html>
<?php
$conn = new mysqli("localhost","root","Divye-2001","myDB");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$course=$_POST["course"];
$notes=$_POST["NotesType"];
$sql1="select * from courses";
$result1=$conn->query($sql1);
$c=0;
while($row1=$result1->fetch_assoc()){
if($row1["Course"]==$course){
$c=1;
break;
}
}
if($c==1){
$sql="SELECT * from ".$course.";";
$result=$conn->query($sql);
while($row=$result->fetch_assoc()){
if($row["notesType"]==$notes){
echo "<script>alert('Course name already has the following name of material');
document.location= 'add1.php'</script>";
}
}
}
if(!is_dir("uploads/".$_POST["course"])){
mkdir("uploads/".$_POST["course"]);
}
$target_dir = "uploads/".$_POST["course"]."/";
$target_file = $target_dir .$_POST["NotesType"].'.'. strtolower(pathinfo($_FILES["filetoUpload"]["name"],PATHINFO_EXTENSION)) ;
echo $target_file;
echo $_FILES["filetoUpload"];
$uploadOk = 1;
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
} else {
if (move_uploaded_file($_FILES["filetoUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["filetoUpload"]["name"]). " has been uploaded.";
} else {
echo $_FILES["filetoUpload"]["error"];
}
}
$sql = "SELECT * from courses;";
$sql1="Insert into ". $_POST["course"]." (notesType,filePath,downloads,dateadded) values ('".$_POST["NotesType"]."','".$target_file."',0,'".date("Y-m-d")."');";
$sql2="Create table ".$_POST["course"]." (notesType VARCHAR(30) NOT NULL,filePath VARCHAR(100),downloads INT,dateadded DATE);";
$sql3="Insert into courses (Course) values ('".$_POST["course"]."');";
$result = $conn->query($sql);
$upload=0;
while($row = $result->fetch_assoc()) {
if($row["Course"]==$_POST["course"]){
$conn->query($sql1);
// echo "inserted in ongoing course";
$upload=1;
break;
}
}
if($upload==0){
if ($conn->query($sql3) === TRUE) {
// echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// mkdir($_POST["course"]);
$conn->query($sql2);
$conn->query($sql1);
}
echo "<script>alert('submitted');
document.location='index.php'</script>";
exit;
$conn->close();
?>