-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditEntrance.php
172 lines (98 loc) · 4.14 KB
/
editEntrance.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
MyDiary Edit Entrance
</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<?php require_once('fade.php');?>
</head>
<?php
$_SESSION['EntranceId'] = $_GET['id'];
require_once('connection.php');
$sql = "SELECT * FROM diary WHERE EntranceID = " . $_GET['id'];
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_array($result)){
$title = $row['EntranceTitle'];
$date = $row['EntranceDate'];
$text = $row['EntranceText'];
}
}else{
Header("Location: hub.php");
Exit();
}
}else{
Header("Location: hub.php");
Exit();
}
?>
<body id="container">
<?php
if($_SESSION['UserID'] <= 0){
require_once('navbar.php');
}else{
require_once('loggedNavbar.php');
}
?>
<div class="container" style="margin-top: 10%;">
<h1>Edit Diary Entrance</h1>
<p></p>
<form action="update.php" method="post">
<div class="form-group">
<label for="entranceTitle">Title:</label>
<input type="text" name="entranceTitle" id="entranceTitle" onkeyup="validateInput('entranceTitle')" class="form-control" value="<?php echo $title; ?>">
</div>
<div class="form-group">
<label for="entranceDate">Date:</label>
<input type="date" name="entranceDate" class="form-control" value="<?php echo $date; ?>">
</div>
<div class="form-group">
<label for="entranceText">Entrance Text:</label>
<textarea class="form-control" name="entranceText" onkeyup="validateInput('inputText')" id="inputText" onkeydown="breakLine(event.keyCode)" rows="5">
<?php echo $text; ?>
</textarea>
</div>
<div class="errorMessage lead" style="padding-left: 1vw; padding-right: 1vw; color: red;">
<p id="errorMessageText"></p>
</div>
<div class="form-group">
<input type="submit" id="editButton" value="Edit" class="btn btn-primary btn-lg" style="float: right;">
</div>
</form>
</div>
</body>
<script>
// function breakLine(keyCode){
// if (keyCode == 13){
// document.getElementById('inputText').value += '<br>';
// }else if(keyCode == 222){
// document.getElementById('inputText').value += "'";
// }
// }
function validateInput(elementName){
input = document.getElementById(elementName).value;
if(input.length <= 0){
if(elementName == 'entranceTitle'){
document.getElementById('errorMessageText').innerHTML = "Come on. You can't leave your title empty...";
document.getElementById('editButton').style.visibility = "hidden";
}else if(elementName == 'inputText'){
document.getElementById('errorMessageText').innerHTML = "Come on. You can't leave your entry empty...";
document.getElementById('editButton').style.visibility = "hidden";
}
}else{
document.getElementById('errorMessageText').innerHTML = '';
document.getElementById('editButton').style.visibility = "visible";
}
}
</script>
</html>