-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
41 lines (33 loc) · 943 Bytes
/
search.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
37
38
39
40
41
<?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['search'])){
$search = cleanData($_GET['search']);
if ($_GET['email'] != ""){ // Honey Pot
exit;
}
# Prepare the search in DB
$statement = $connection->prepare(
'SELECT * FROM articles WHERE
tittle LIKE :search or
content LIKE :search'
);
# Execute the search
$statement->execute(array(':search' => "%$search%"));
$search_found = $statement->fetchAll();
if (empty($search_found)){
$notice = "No articles found with: " . $search;
} else {
$notice = "Articles found with: " . $search;
}
} else {
header('Location: ' . route . '/index.php');
}
require 'views/search.view.php';
?>