-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathara.php
65 lines (58 loc) · 2.22 KB
/
ara.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
require_once './root.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/paper.min.css">
</head>
<body>
<div class="container">
<form action="" method="GET">
<div>
<label for="ara">Search</label><br>
<input type="text" name="ara" id="ara" placeholder="Search keyword..." value="<?php echo htmlspecialchars($_GET['ara'] ?? '', ENT_QUOTES, 'UTF-8'); ?>">
</div>
<div>
<input type="submit" value="Search" name="gonder">
</div>
</form>
</div>
</body>
</html>
<?php
if (isset($_GET['gonder'])) {
$ara = trim($_GET['ara']);
if (!empty($ara)) {
$stmt = $db->prepare("SELECT * FROM posts WHERE title LIKE :searchTerm LIMIT 10");
$stmt->execute(['searchTerm' => "%$ara%"]);
$results = $stmt->fetchAll(PDO::FETCH_OBJ);
if (count($results) > 0) {
foreach ($results as $item) { ?>
<div class="container">
<h2><a href="icerik.php?git=<?php echo htmlspecialchars($item->id, ENT_QUOTES, 'UTF-8'); ?>&aranan=<?php echo htmlspecialchars($ara, ENT_QUOTES, 'UTF-8'); ?>"><?php echo htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8'); ?></a></h2>
<span><?php echo htmlspecialchars($item->content, ENT_QUOTES, 'UTF-8'); ?></span>
</div>
<?php }
} else {
echo '<div class="container">';
echo '<div class="alert alert-danger">No results found for your search!</div>';
echo '</div>';
}
} else {
echo '<div class="container">';
echo '<div class="row flex-spaces">';
echo '<input class="alert-state" id="alert-1" type="checkbox">';
echo '<div class="alert alert-secondary dismissible">';
echo 'Please enter at least one character.';
echo '<label class="btn-close" for="alert-1">X</label>';
echo '</div>';
echo '</div>';
echo '</div>';
}
}
?>