-
Notifications
You must be signed in to change notification settings - Fork 1
/
photo.php
302 lines (258 loc) · 6.37 KB
/
photo.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?php
session_start();
include("header.php");
if(isset($_POST[submit]))
{
$filename = rand() . $_FILES["photo"]["name"];
move_uploaded_file($_FILES["photo"]["tmp_name"],"imgphoto/".$filename);
if(isset($_GET[editid]))
{
$sql ="UPDATE photo set album_id=$_POST[album_id],photo_title=$_POST[photo_title],photo_description=$_POST[photo_description],status=$_POST[status]";
if($_FILES["photo"]["name"] != "")
{
$sql = $sql . " ,photo=$filename";
}
$sql = $sql . " WHERE photo_id=$_GET[editid]";
$qsql = mysqli_query($con,$sql);
if(mysqli_affected_rows($con) == 1)
{
echo "<script>alert( Photo record updated successfully..);</script>";
}
else
{
echo mysqli_error($con);
}
}
else
{
$sql ="INSERT INTO photo(album_id,photo_title,photo_description,status,photo) VALUES($_POST[album_id],$_POST[photo_title],$_POST[photo_description],$_POST[status],$filename)";
$qsql = mysqli_query($con,$sql);
if(mysqli_affected_rows($con) == 1)
{
echo "<script>alert(photo record inserted successfully..);</script>";
echo "<script>window.location=photo.php;</script>";
}
else
{
echo mysqli_error($con);
}
}
}
?>
<?php
if(isset($_GET[editid]))
{
$sqledit = "SELECT * FROM photo WHERE photo_id=$_GET[editid]";
$qsqledit = mysqli_query($con,$sqledit);
$rsedit = mysqli_fetch_array($qsqledit);
}
?>
<div id="page-header">
<div class="section-bg" style="background-image: url(img/background-2.jpg);"></div>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="header-content">
<h1>Photo</h1>
</div>
</div>
</div>
</div>
</div>
</header>
<div class="section" style="padding-top: 1px;">
<div class="container">
<div class="row">
<main id="" class="col-md-12">
<div class="">
<div class="">
<div class="article-comments">
<div class="media">
<div class="media-left">
<img class="media-object" src="img/charity.jpg" style="width: 100px;height: 100px;">
</div>
<div class="media-body">
<div class="media-heading">
<h4>Photo</h4>
</div>
<p>
<form method="post" action="" enctype="multipart/form-data" onsubmit="return validateform()">
<div class="row">
<div class="col-md-2" style="padding-top: 5px;"> Album</div>
<div class="col-md-10">
<select id="album_id" name="album_id" class="form-control">
<option value="">Select album</option>
<?php
$sqlalbum = "SELECT * FROM album WHERE status=Active";
$qsqlalbum = mysqli_query($con,$sqlalbum);
while($rsalbum = mysqli_fetch_array($qsqlalbum))
{
if($rsalbum[album_id] == $rsedit[album_id])
{
echo "<option value=$rsalbum[album_id] selected>$rsalbum[album_title]</option>";
}
else
{
echo "<option value=$rsalbum[album_id]>$rsalbum[album_title]</option>";
}
}
?>
</select>
<span id="erralbum_id" class="errorclass"></span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2" style="padding-top: 5px;"> Photo Title </div>
<div class="col-md-10">
<input type="text" name="photo_title" id="photo_title" class="form-control" value="<?php echo $rsedit[photo_title]; ?>">
<span id="errphoto_title" class="errorclass"></span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2" style="padding-top: 5px;"> Photo </div>
<div class="col-md-10">
<input type="file" name="photo" id="photo" class="form-control" accept="image/*" >
<?php
if(isset($_GET[editid]))
{
echo "<img src=imgphoto/$rsedit[photo] style=width: 360px; height: 300px;>";
}
?>
<span id="errphoto" class="errorclass"></span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2" style="padding-top: 5px;"> Photo Description </div>
<div class="col-md-10">
<textarea name="photo_description" id="photo_description" class="form-control"><?php echo $rsedit[photo_description]; ?></textarea>
<span id="errphoto_description" class="errorclass"></span>
</div>
</div>
<span id="errphoto_description" class="errorclass"></span>
<br>
<div class="row">
<div class="col-md-2" style="padding-top: 5px;">Status</div>
<div class="col-md-10">
<select class="form-control" name="status" id="status">
<option value="">Select Status</option>
<?php
$arr = array("Active","Inactive");
foreach($arr as $val )
{
if($val == $rsedit[status]){echo "<option value=$val selected>$val</option>";} else {echo "<option value=$val>$val</option>";}
}
?>
</select>
<span id="errstatus" class="errorclass"></span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2" style="padding-top: 5px;"></div>
<div class="col-md-10">
<input type="submit" name="submit" id="submit" class="form-control btn btn-success" style="width: 200px;">
</div>
</div>
</form>
</p>
</div>
</div>
</div>
</div>
</main>
</div>
</div>
</div>
<?php
include("footer.php");
?>
<?php
if(isset($_GET[editid]))
{
?>
<script>
function validateform()
{
var i = 0;
$(.errorclass).html();
if(document.getElementById("album_id").value=="")
{
document.getElementById("erralbum_id").innerHTML = "Kindly select album...";
i = 1;
}
if(document.getElementById("photo_title").value=="")
{
document.getElementById("errphoto_title").innerHTML = "Kindly enter Photo title....";
i = 1;
}
if(document.getElementById("photo_description").value=="")
{
document.getElementById("errphoto_description").innerHTML = "Photo description should not be empty...";
i = 1;
}
if(document.getElementById("status").value=="")
{
document.getElementById("errstatus").innerHTML = "Kindly select status...";
i = 1;
}
if(i == 0)
{
return true;
}
else
{
return false;
}
}
</script>
<?php
}
else
{
?>
<script>
function validateform()
{
var i = 0;
$(.errorclass).html();
if(document.getElementById("album_id").value=="")
{
document.getElementById("erralbum_id").innerHTML = "Kindly select album...";
i = 1;
}
if(document.getElementById("photo_title").value=="")
{
document.getElementById("errphoto_title").innerHTML = "Kindly enter Photo title....";
i = 1;
}
if(document.getElementById("photo").value=="")
{
document.getElementById("errphoto").innerHTML = "Kindly upload the photo....";
i = 1;
}
if(document.getElementById("photo_description").value=="")
{
document.getElementById("errphoto_description").innerHTML = "Photo description should not be empty...";
i = 1;
}
if(document.getElementById("status").value=="")
{
document.getElementById("errstatus").innerHTML = "Kindly select status...";
i = 1;
}
if(i == 0)
{
return true;
}
else
{
return false;
}
}
</script>
<?php
}
?>