Add article creation
This commit is contained in:
@@ -6,7 +6,7 @@ function getNewsArticles() :array
|
||||
|
||||
$articles = [];
|
||||
if (isLoggedIn()) {
|
||||
$result = $mysqli->query("SELECT NewsArticles.ID, NewsArticles.WrittenAt, NewsArticles.WrittenBy, NewsArticles.Title, NewsArticles.Body, NewsArticles.FileList Users.Nickname FROM NewsArticles INNER JOIN Users ON NewsArticles.WrittenBy = Users.ID; ");
|
||||
$result = $mysqli->query("SELECT NewsArticles.ID, NewsArticles.WrittenAt, NewsArticles.WrittenBy, NewsArticles.Title, NewsArticles.Body, NewsArticles.FileList, Users.Nickname FROM NewsArticles INNER JOIN Users ON NewsArticles.WrittenBy = Users.ID; ");
|
||||
|
||||
// Check if the query executed Successfully
|
||||
if ($result) {
|
||||
@@ -17,4 +17,21 @@ function getNewsArticles() :array
|
||||
}
|
||||
|
||||
return $articles;
|
||||
}
|
||||
|
||||
function addNewsArticle($title="Nazov", $body="Obsah") :array
|
||||
{
|
||||
global $mysqli;
|
||||
|
||||
$output = ["Status" => "Fail"]; // Default Status is "Fail"
|
||||
if (isLoggedIn()) {
|
||||
$query = $mysqli->prepare("INSERT INTO NewsArticles (WrittenBy, Title, Body, FileList) VALUES (?, ?, ?, ?);");
|
||||
$query->bind_params("issi", $_SESSION["id"], htmlspecialchars($title), htmlspecialchars($body), 0);
|
||||
$query->execute();
|
||||
if ($query->affected_rows > 0) {
|
||||
$output["Status"] = "Success";
|
||||
}
|
||||
}
|
||||
$query->close();
|
||||
return $output;
|
||||
}
|
Reference in New Issue
Block a user