<?php
session_start();
require "config.php";
$categories_id = $_POST['id'];
$title = $_POST['title'];
$text = $_POST['text'];
$date = date("Y.m.d");
$path = 'static/images/' . time() . $_FILES['image']['name'];
move_uploaded_file($_FILES['image']['tmp_name'], '../' . $path);
if(!move_uploaded_file($_FILES['image']['tmp_name'], '../' . $path)) {
$_SESSION['message'] = 'Ошибка при загрузке фотографии!';
header('Location: ../admin.php');
}
mysqli_query($connection, "INSERT INTO `articles` (`id`, `title`, `image`, `text`, `categorie_id`, `pubdate`, `views`) VALUES (NULL, '$title', '$path', '$text', '$categories_id', '$date', '0')");
$_SESSION['message'] = 'Статья добавлена';
?>
<?php
session_start();
require "config.php";
$idnews = $_POST["id"];
$query = mysqli_query($connection, "SELECT * FROM `articles` WHERE `id` = '$idnews'");
if (mysqli_num_rows($query) > 0) {
mysqli_query($connection, "DELETE FROM `articles` WHERE `id` = '$idnews'");
$_SESSION['message'] = 'Статья успешно удалена!';
header('Location: ../admin.php');
} else {
$_SESSION['message'] = 'Статья с данным ID не найдена!';
header('Location: ../admin.php');
}
?>
session_start();
require "config.php";
$deleted = $_POST['deleted'];
if ($deleted) {
removeArticle();
} else {
addArticle();
}
function addArticle()
{
$categories_id = $_POST['id'];
$title = $_POST['title'];
$text = $_POST['text'];
$date = date("Y.m.d");
$path = 'static/images/' . time() . $_FILES['image']['name'];
move_uploaded_file($_FILES['image']['tmp_name'], '../' . $path);
if(!move_uploaded_file($_FILES['image']['tmp_name'], '../' . $path)) {
$_SESSION['message'] = 'Ошибка при загрузке фотографии!';
header('Location: ../admin.php');
}
mysqli_query($connection, "INSERT INTO `articles` (`id`, `title`, `image`, `text`, `categorie_id`, `pubdate`, `views`) VALUES (NULL, '$title', '$path', '$text', '$categories_id', '$date', '0')");
$_SESSION['message'] = 'Статья добавлена';
}
function removeArticle()
{
$idnews = $_POST["id"];
$query = mysqli_query($connection, "SELECT * FROM `articles` WHERE `id` = '$idnews'");
if (mysqli_num_rows($query) > 0) {
mysqli_query($connection, "DELETE FROM `articles` WHERE `id` = '$idnews'");
$_SESSION['message'] = 'Статья успешно удалена!';
header('Location: ../admin.php');
} else {
$_SESSION['message'] = 'Статья с данным ID не найдена!';
header('Location: ../admin.php');
}
}