-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinsert_document.php
More file actions
98 lines (81 loc) · 2.65 KB
/
insert_document.php
File metadata and controls
98 lines (81 loc) · 2.65 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
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
<?php
//inserts document into the database
session_start();
if ($db_conn=OCILogon("ora_p1t7", "a36959104", "ug")) {
$email = $_SESSION['email'];
$course = $_SESSION[('course' . (string)$_POST['courseSelect'])];
$docURL = $_POST['docURL'];
$docName = $_POST['docname'];
$docId = 1;
//find largest document id
$cmdstr = "select max(document_id) from document";
$parsed = OCIParse($db_conn, $cmdstr); // parse the statement
if (!$parsed){
$e = OCIError($db_conn);
$_SESSION['insert_document_result'] = htmlentities($e['message']);
header("location:doc_upload.php");
exit;
}
$r=OCIExecute($parsed, OCI_DEFAULT);
if (!$r){
$e = oci_error($parsed);
$_SESSION['insert_document_result'] = htmlentities($e['message']);
header("location:doc_upload.php");
exit;
}
$row = OCI_Fetch_Array($parsed, OCI_NUM);
if (empty($row)) {
$_SESSION['insert_document_result'] = "Internal server error";
OCILogoff($db_conn);
header('Location: noteshare.php');
}
else {
$docId += $row[0];
}
//insert document
$cmdstr = "insert into document values($docId, '$docName', default, '$docURL', '$course[0]', '$course[2]', '$course[3]', '$course[4]', $course[5], '$email')";
$parsed = OCIParse($db_conn, $cmdstr); // parse the statement
if (!$parsed){
$e = OCIError($db_conn);
$_SESSION['insert_document_result'] = htmlentities($e['message']);
header("location:doc_upload.php");
exit;
}
$r=OCIExecute($parsed, OCI_DEFAULT);
if (!$r){
$e = oci_error($parsed);
$_SESSION['insert_document_result'] = htmlentities($e['message']);
header("location:doc_upload.php");
exit;
}
OCICommit($db_conn);
echo("insert worked");
$cmdstr = "select * from document where document_id = $docId";
$parsed = OCIParse($db_conn, $cmdstr);
if (!$parsed){
$e = OCIError($db_conn);
$_SESSION['insert_document_result'] = htmlentities($e['message']);
header("location:doc_upload.php");
exit;
}
$r=OCIExecute($parsed, OCI_DEFAULT);
if (!$r){
$e = oci_error($parsed);
$_SESSION['insert_document_result'] = htmlentities($e['message']);
header("location:doc_upload.php");
exit;
}
$row = OCI_Fetch_Array($parsed, OCI_NUM);
if (empty($row)) {
$_SESSION['insert_document_result'] = "Fail";
header("location:doc_upload.php");
}
OCILogoff($db_conn);
$_SESSION['insert_document_result'] = "Success!";
header("location:doc_upload.php");
}
else {
$e = OCIError();
echo htmlentities($e['message']);
}
?>