-
Notifications
You must be signed in to change notification settings - Fork 0
/
editpost.php
68 lines (53 loc) · 1.84 KB
/
editpost.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
<?php
require('config/config.php');
require('config/db.php');
if(isset($_POST['submit'])){
//get from data
$update_id=mysqli_real_escape_string($conn,$_POST['update_id']);
$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 posts SET
title='$title',
author='$author',
body='$body'
where id={$update_id}";
if(mysqli_query($conn,$query)){
header('Location:'.ROOT_URL.'');
}else{
echo "ERROR".mysqli_error($conn);
}
}
$id=mysqli_real_escape_string($conn,$_GET['id']);
//create query
$query='select * from posts where id='.$id;
//get result
$result=mysqli_query($conn,$query);
//fetch data
$post=mysqli_fetch_assoc($result);
//var_dump($posts);
//free the result
mysqli_free_result($result);
mysqli_close($conn);
?>
<?php include('inc/header.php'); ?>
<div class="container mt-5">
<h1>Add Posts</h1>
<form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>">
<div class="form-group">
<label for="title">Enter Post Title</label>
<input type="text" class="form-control" name="title" value="<?php echo$post['title'] ; ?>">
</div>
<div class="form-group">
<label for="author">Author</label>
<input type="text" class="form-control" name="author" value="<?php echo$post['author'] ; ?>">
</div>
<div class="form-group">
<label for="body">Body</label>
<textarea type="text" class="form-control" name="body"> "<?php echo$post['body'] ; ?>" </textarea>
</div>
<input type="hidden" name="update_id" value= "<?php echo$post['id'] ; ?>">
<button type="submit" name="submit" class="btn btn-outline-secondary">Submit</button>
</form>
</div>
<?php include('inc/footer.php'); ?>