001.
<?php
002.
003.
require_once
"connect.php"
;
004.
005.
session_start();
006.
007.
if
(isset(
$_GET
[
'edit'
])) {
008.
$edit_id
=
$_GET
[
'edit'
];
009.
010.
$edit_query
=
"SELECT * FROM posts WHERE post_id = '$edit_id'"
;
011.
012.
$run_edit
= mysqli_query(
$conn
,
$edit_query
);
013.
014.
while
(
$edit_row
= mysqli_fetch_array(
$run_edit
)) {
015.
$post_id
=
$edit_row
[
'post_id'
];
016.
$post_title
=
$edit_row
[
'post_title'
];
017.
$post_author
=
$edit_row
[
'post_author'
];
018.
$post_date
=
date
(
'y-m-d'
);
019.
$post_keywords
=
$edit_row
[
'post_keywords'
];
020.
$post_image
=
$edit_row
[
'post_image'
];
021.
$post_content
=
$edit_row
[
'post_content'
];
022.
023.
}
024.
}
025.
026.
if
(isset(
$_POST
[
'submit'
])) {
027.
$update_id
=
$_GFET
[
'edit_form'
];
028.
$post_title
=
$_POST
[
'title'
];
029.
$post_date
=
date
(
'y-m-d'
);
030.
$post_author
=
$_POST
[
'author'
];
031.
$post_keywords
=
$_POST
[
'keywords'
];
032.
$post_content
=
$_POST
[
'content'
];
033.
$post_image
=
$_FILES
[
'image'
][
'name'
];
034.
$image_tmp
=
$_FILES
[
'image'
][
'temp_name'
];
035.
036.
move_uploaded_file(
$image_tem
,
"../img/$post_image"
);
037.
038.
$update_query
= "UPDATE posts SET post_title =
'$post_title'
, post_date =
'$post_date'
, post_author =
'$post_author'
,
039.
post_image =
'$post_image'
, post_keywords =
'$post_keywords'
, post_content =
'$post_content'
WHERE post_id =
'$update_id'
";
040.
041.
if
(mysqli_query(
$conn
,
$update_query
)) {
042.
echo
"<script>alert('Post has been updated');</script>"
;
043.
header(
"location: view_posts.php"
);
044.
}
else
{
045.
echo
"<script>alert('Something wrong!');</script>"
;
046.
}
047.
}
048.
049.
?>
050.
051.
<!DOCTYPE html>
052.
<html lang=
"en"
dir=
"ltr"
>
053.
<head>
054.
<meta charset=
"utf-8"
>
055.
<title>View Post Page</title>
056.
057.
<link rel=
"stylesheet"
href=
"css/adminstyle.css"
>
058.
059.
060.
</head>
061.
<body>
062.
063.
<header>
064.
<div
class
=
"container"
>
065.
<h1>Welcome to Admin Page Miss.</h1>
066.
067.
</div>
068.
</header>
069.
070.
<section
class
=
"content"
>
071.
<div
class
=
"content_grid"
>
072.
073.
<div
class
=
"sidebar"
>
074.
<h1>Welcome : </h1>
075.
<h3><a href=
"index.php"
>Home</a></h3>
076.
<h3><a href=
"view_posts.php"
>View Posts</a></h3>
077.
<h3><a href=
"insert_post.php"
>Insert Post</a></h3>
078.
<h3><a href=
"logout.php"
>Logout</a></h3>
079.
</div>
080.
081.
<div
class
=
"showinfo"
>
082.
<h1>Edit Post</h1>
083.
084.
<form action=
"edit_post.php?edit_form=<?php echo $post_id; ?>"
method=
"post"
enctype=
"multipart/form-data"
>
085.
086.
<table width=
"100%"
align=
"center"
border=
"1"
>
087.
<tr>
088.
<td align=
"center"
colspan=
"6"
><h1>Edit Post</h1></td>
089.
</tr>
090.
091.
<tr>
092.
<td>Post Title</td>
093.
<td><input type=
"text"
name=
"title"
size=
"50"
value=
"<?php echo $post_title; ?>"
></td>
094.
</tr>
095.
096.
<tr>
097.
<td>Post Author</td>
098.
<td><input type=
"text"
name=
"author"
size=
"50"
value=
"<?php echo $post_author; ?>"
></td>
099.
</tr>
100.
101.
<tr>
102.
<td>Post Keywords</td>
103.
<td><input type=
"text"
name=
"keywords"
size=
"50"
value=
"<?php echo $post_keywords; ?>"
></td>
104.
</tr>
105.
106.
<tr>
107.
<td>Post Image</td>
108.
<td><input type=
"file"
name=
"image"
size=
"50"
><img width=
"150"
height=
"150"
src=
"../img/<?php echo $post_image; ?>"
alt=
""
></td>
109.
</tr>
110.
111.
<tr>
112.
<td>Post Content</td>
113.
<td><textarea name=
"content"
cols=
"50"
rows=
"15"
><?php
echo
$post_content
; ?></textarea></td>
114.
</tr>
115.
116.
<tr>
117.
<td align=
"center"
colspan=
"6"
><input type=
"submit"
name=
"submit"
value=
"Update Now"
></td>
118.
</tr>
119.
</table>
120.
</form>
121.
122.
123.
<img width=
"640"
height=
"360"
src=
"img/admin.jpg"
alt=
""
>
124.
125.
</div>
126.
</div>
127.
128.
</section>
129.
130.
</body>
131.
</html>