-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthor.php
36 lines (29 loc) · 846 Bytes
/
author.php
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
<?php
require 'admin/config.php';
require 'functions.php';
# Call Connection
$connection = connection($db_config);
if (!$connection) {
header('Location: error.php');
}
# Receive the search
if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET['author'])){
$search = cleanData($_GET['author']);
# Prepare the search in DB
$statement = $connection->prepare(
'SELECT * FROM articles WHERE
author LIKE :author'
);
# Execute the search
$statement->execute(array(':author' => "%$search%"));
$search_found = $statement->fetchAll();
if (empty($search_found)){
$notice = "There are no articles by this author";
} else {
$notice = "Articles by the author: " . $search;
}
} else {
header('Location: ' . route . '/index.php');
}
require 'views/search.view.php';
?>