-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathedit.php
More file actions
58 lines (46 loc) · 1.48 KB
/
Copy pathedit.php
File metadata and controls
58 lines (46 loc) · 1.48 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
<?php
if(!isset($_SESSION['username'])) {
header("location: loginblog.php");
}
include("header.php");
include("connect.php");
$id = (INT) $_GET['id'];
if($id < 1) {
header("location: index.php");
}
$sql = "SELECT * FROM posts WHERE id = '$id'";
$result = mysqli_query($dbcon, $sql);
if(mysqli_num_rows($result) ==0) {
header("location: index.php");
}
$row = mysqli_fetch_assoc($result);
$id = $row['id'];
$title = $row['title'];
$description = $row['description'];
if(isset($_POST['upd'])) {
$id = $_POST['id'];
$title = mysqli_real_escape_string($dbcon, $_POST['title']);
$description = mysqli_real_escape_string($dbcon, $_POST['description']);
$sql2 = "UPDATE posts SET title = '$title', description = '$description' WHERE id = $id";
if(mysqli_query($dbcon, $sql2)) {
// or die("failed to edit. ". mysqli_connect_error());
echo "Post edited successfully.";
echo "<meta http-equiv='refresh' content='2; url=view.php?id=$id' />";
}
else {
echo "failed to edit.". mysqli_connect_error();
}
}
?>
<form action="" method="POST" class="w3-container">
<input type="hidden" name="id" value="<?php echo $id;?>">
<label>Title</label>
<input type="text" class="w3-input w3-border" name="title" value="<?php echo $title;?>">
<label>Description</label>
<textarea class="w3-input w3-border" name="description"><?php echo $description;?> </textarea>
<input type="submit" class="w3-btn w3-green w3-round" name="upd" value="Edit">
</form>
<?php
mysqli_close($dbcon);
include("footer.php");
?>