-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathedit.php
More file actions
executable file
·58 lines (47 loc) · 1.47 KB
/
edit.php
File metadata and controls
executable file
·58 lines (47 loc) · 1.47 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
include 'includes.php';
session_start();
if($_SESSION['isAdmin']) {
//is logged in and is admin
if(!isset($_POST['submit'])) {
//Get variables from POST method
$postId = $_SESSION['post_id'] = $_GET['post_id'];
//Get access to blog that's getting edited
Connect();
mysql_select_db('blog');
$sql = "SELECT * FROM blog_posts WHERE id = '$postId'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
Disconnect();
//Setting session variables
$_SESSION['blogpost_editor'] = "edit.php";
$_SESSION['title'] = "Edit a";
$_SESSION['blog_entry'] = $row;
header("Location: blogpost_editor.php");
} else {
$title = addslashes($_POST['title']);
$blog = addslashes($_POST['blog']);
if(!empty($title) && !empty($blog)) {
//Saving the post to SQL
Connect();
mysql_select_db('blog');
$author_id = $_SESSION['author_id'];
$postId = $_SESSION['post_id'];
$sql = "UPDATE blog_posts SET title='$title', post='$blog' WHERE id='$postId'";
mysql_query($sql);
Disconnect();
//Success
$success = true;
header("Location: view.php");
} else {
$error_msg = "Please fill in all fields before continuing";
$success = false;
}
//unset session vars
}
} elseif($_SESSION['isClient']) {
//logged in as a client => go back to public_view
} else {
header("Location: login.php");
}
?>