-
Notifications
You must be signed in to change notification settings - Fork 2
/
contentEdit.php
122 lines (107 loc) · 5.1 KB
/
contentEdit.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
<?php
include 'config.php';
session_start();
if (isset($_SESSION['user_name']) && isset($_SESSION['COO_id'])) {
$content_id = $_GET['editContent'];
// content details
$sql = "SELECT * FROM content WHERE content_id= '$content_id' ";
$result = mysqli_query($conn, $sql);
$content = mysqli_fetch_array($result);
$content_id = $content["content_id"];
$content_name = $content['content_name'];
$content_title = $content['content_title'];
$content_link = $content['content_link'];
$content_serial_no = $content['content_serial_no'];
$content_description = $content['content_description'];
$content_detail_text = $content['content_detail_text'];
$content_week = $content['week_id'];
//content type
$myQuery = "SELECT content_type FROM content_content_type WHERE content_id = '$content_id' ";
$myQueryResult = mysqli_query($conn, $myQuery);
$content_type = mysqli_fetch_array($myQueryResult);
$content_type = $content_type['content_type'];
//week details
$sq = "SELECT * FROM week WHERE week_id= '$content_week' ";
$rlt = mysqli_query($conn, $sq);
$week = mysqli_fetch_array($rlt);
$week_id = $week["week_id"];
$week_title = $week["week_title"];
$week_number = $week["week_number"];
$subject_id = $week["subject_id"];
// subject details
$sql = "SELECT * FROM subject WHERE subject_id= '$subject_id' ";
$result = mysqli_query($conn, $sql);
$subject = mysqli_fetch_array($result);
$subject_id = $subject["subject_id"];
$subject_name = $subject["subject_name"];
?>
<!--- if update button clicked --->
<?php
if (isset($_POST['update'])) {
$content_name = $_POST['content_name'];
$content_title = $_POST['content_title'];
$content_link = $_POST['content_link'];
$content_type = $_POST['content_type'];
$content_serial_no = $_POST['content_serial_no'];
$content_description = $_POST['content_description'];
$content_detail_text = $_POST['content_detail_text'];
// update content in content table query
$sq = "UPDATE content SET content_name = '$content_name', content_title = '$content_title',
content_link = '$content_link',
content_serial_no = '$content_serial_no',
content_description = '$content_description',
content_detail_text = '$content_detail_text' WHERE content_id = '$content_id'";
mysqli_query($conn, $sq);
// update content_type in content_content_type table query
$sqry = "UPDATE content_content_type SET content_type = '$content_type' WHERE content_id = '$content_id'";
mysqli_query($conn, $sqry);
//catching subject name of a week_id for showing in contents page
//$ql = "SELECT * FROM subject WHERE subject_id=(SELECT subject_id FROM week WHERE week_id = '$week_id')";
//$rlt = mysqli_query($conn, $ql);
//$subject = mysqli_fetch_array($rlt);
$_SESSION['subject_id'] = $subject_id;
$_SESSION['subject_name'] = $subject_name;
$_SESSION['week_id'] = $week_id;
$_SESSION['week_title'] = $week_title;
$_SESSION['week_number'] = $week_number;
header("Location: contents.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>contentEdit</title>
</head>
<body>
<div><?php echo "<h1>Update " . $subject_name . "'s week number : " . $week_number . " ==> " . $week_title . "</h1>" ?></div>
<div>
<form action="" method="POST">
<h2>content title : </h2>
<input type="text" placeholder="content_title" name="content_title" value="<?php echo $content_title; ?>">
<h2>content serial no : </h2>
<input type="number" min="01" max="9999" placeholder="content_serial_no" name="content_serial_no" value="<?php echo $content_serial_no; ?>">
<h2>content name : </h2>
<input type="text" placeholder="content_name" name="content_name" value="<?php echo $content_name; ?>">
<h2>content type : </h2>
<input type="text" placeholder="content_type" name="content_type" value="<?php echo $content_type; ?>">
<h2>content link : </h2>
<input type="text" placeholder="content_link" name="content_link" value="<?php echo $content_link; ?>">
<h2>content description : </h2>
<textarea id="content_description" name="content_description" rows="15" cols="70">
<?php echo $content_description; ?>
</textarea>
<h2>content detail_text : </h2>
<textarea id="content_detail_text" name="content_detail_text" rows="15" cols="70">
<?php echo $content_detail_text; ?>
</textarea>
<button type="submit" name="update">UPDATE</button>
</form>
</div>
</body>
</html>
<?php } else {
header("Location: teacherLogin.php");
} ?>