Show sourcecode

The following files exists in this folder. Click to view.

Foogler_blog/pages

PAuthor.php
PCommentProcess.php
PDeleteCommentProcess.php
PDeletePost.php
PDeletePostProcess.php
PEditPost.php
PEditPostProcess.php
PErDiagramme.php
PIndex.php
PInstall.php
PInstallProcess.php
PNewPost.php
PNewPostProcess.php
PRssFeed.php
PShowPost.php
PStatistics.php
PValidate.php
login/

PEditPostProcess.php

122 lines ASCII Windows (CRLF)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
//--------------------------
// PEditPostProcess.php
//
// Performs process for editing post
//--------------------------

//Note: At the moment it's not possible to remove tags

//Checks that user is logged in
if(!isset($_SESSION['accountUser'])) {
  require_once(
"login/PLogin.php");
  exit;  
} else if(
$_SESSION['accountUser'] == "guest" ) {
  die(
"Sorry, you don't have the priviliges for doing this...");
}

//--------------------------
//Handles POST variables
$idPost = isset($_POST['idPost']) ? $_POST['idPost'] : '';
$postTitle  = isset($_POST['postTitle']) ? $_POST['postTitle'] : '';
$postText = isset($_POST['postText']) ? $_POST['postText'] : '';
$tags = isset($_POST['tags']) ? $_POST['tags'] : '';

//--------------------------
//DB stuff
$mysqli = new mysqli(DB_HOSTDB_USERDB_PASSWORDDB_DATABASE); //New DB object

if (mysqli_connect_error()) {
   echo 
"Connect failed: ".mysqli_connect_error()."<br>";
   exit();
}
$mysqli->set_charset("utf8");

//Prevent SQL injections
$postTitle       $mysqli->real_escape_string($postTitle);
$postText     $mysqli->real_escape_string($postText);
$tags      $mysqli->real_escape_string($tags);
$idPost      $mysqli->real_escape_string($idPost);

//------------------------
//SQL query
$tablePost DB_PREFIX 'Post';
$tableTag DB_PREFIX 'Tag';
$tablePostTag DB_PREFIX 'PostTag';

$query = <<<END
--
-- Edits post
--
UPDATE 
{$tablePost}
SET
  postTitle = '
{$postTitle}',
  postText = '
{$postText}'
WHERE
  idPost = 
{$idPost};  
END;

$tagArray explode(','$tags); //Separates string with tags

//For each tag, makes sure it doesn't already exist - if it doesn't, adds the tag to DB
foreach($tagArray as $tag) {
  
$tag trim($tag); //Removes whitespace around tag
  
  //-------------------
  //SQL query
  
$queryTwo = <<<END
  --
  -- Selects tag by name
  --
  SELECT idTag FROM 
{$tableTag} WHERE tagName = '{$tag}';
END;
  
  
//Performs query
  
$res $mysqli->query($queryTwo) or die("Could not query database" $mysqli->errno " : " $mysqli->error); 
  
  
//If the previous query didn't yield any results, adds query to insert new tag
  
if($res->num_rows == 0) {
    
$query .= <<<END
    --
    -- Adds new tag
    --
    INSERT INTO 
{$tableTag}(tagName) VALUES ('{$tag}');
END;
  }
  
$res->close();
  
  
//-----------------
  //SQL query
  
$queryTwo = <<<END
  --
  -- Selects tag + post connection for chosen post and current tag
  --
  SELECT * FROM 
{$tablePostTag} 
  WHERE PostTag_idPost = 
{$idPost} 
    AND PostTag_idTag = (SELECT idTag FROM 
{$tableTag} WHERE tagName = '{$tag}');
END;
  
//Performs query
  
$res $mysqli->query($queryTwo) or die("Could not query database" $mysqli->errno " : " $mysqli->error); 
  
  
//If the previous query didn't yield any results, adds query to insert tag + post connection
  
if($res->num_rows == 0) {
  
$query .= <<<END
  --
  -- Adds post + tag connection
  --
  INSERT INTO 
{$tablePostTag} (PostTag_idPost, PostTag_idTag)
    VALUES (
{$idPost}, (SELECT idTag FROM {$tableTag} WHERE tagName = '{$tag}'));
END;
  }
  
$res->close();
}

//Performs multiple queries
$res $mysqli->multi_query($query) or die("Could not query database" $mysqli->errno " : " $mysqli->error); 
$mysqli->close(); //Closes DB connection

//---------------------
//Redirects to post page
header("Location:" WS_SITELINK "?p=post&id=" $idPost);
exit;