-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditpost.php
More file actions
64 lines (52 loc) · 1.96 KB
/
editpost.php
File metadata and controls
64 lines (52 loc) · 1.96 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
<?php
require('conf/db.php');
require('conf/conf.php');
if(isset($_POST['submit'])){
$updateid=mysqli_real_escape_string($conn,$_POST['updateid']);
$title =mysqli_real_escape_string($conn,$_POST['title']);
$body =mysqli_real_escape_string($conn, $_POST['body']);
$author =mysqli_real_escape_string($conn, $_POST['author']);
$query ="UPDATE post SET title='$title',author='$author',
body='$body' WHERE id = $updateid" ;
if(mysqli_query($conn,$query)){
header('Location:'.ROOT_URL.'main.php');
} else {
echo mysqli_error($conn);
}
}
$id = mysqli_real_escape_string($conn,$_GET['id']);
$query = 'SELECT * FROM post WHERE id = '.$id;
$result =mysqli_query($conn,$query);
$post =mysqli_fetch_assoc($result);
mysqli_free_result($result);
mysqli_close($conn);
?>
<!DOCTYPE html>
<html>
<head>
<title>BLOG</title>
<link rel="stylesheet" type="text/css" href="conf/bootstrap.min.css">
</head>
<body>
<?php include('navbar.php'); ?>
<div class="container">
<h1>Add Post</h1>
<form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>">
<div class="form-group">
<label class="col-form-label" for="inputDefault">Title</label>
<input name="title" value="<?php echo $post['title']; ?>" type="text" class="form-control" id="inputDefault">
</div>
<div class="form-group">
<label class="col-form-label" for="inputDefault">Author</label>
<input name="author" type="text" value="<?php echo $post['author']; ?>" class="form-control" id="inputDefault">
</div>
<div class="form-group">
<label for="exampleTextarea">What's on your mind?</label>
<textarea name='body' class="form-control" id="exampleTextarea" rows="3" spellcheck="false"><?php echo $post['body']; ?></textarea>
</div>
<input type="hidden" name="updateid" value="<?php echo $post['id']; ?>">
<button name="submit" value="Submit" type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</body>
</html>