-
Notifications
You must be signed in to change notification settings - Fork 0
/
picture.php
75 lines (65 loc) · 1.48 KB
/
picture.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
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html>
<title>Pictures</title>
<body>
<?php
include "loadPicDatabase.php";
// This will retrieve scriptures from the database
function getPicSite($id) {
$conn = loadDatabase();
try {
$sql = 'SELECT * FROM picture';
$stmt = $conn->prepare($sql);
$stmt->execute();
$data = $stmt->fetchAll();
$stmt->closeCursor();
} catch (PDOException $ex) {
echo 'PDO error in model.';
}
if (is_array($data)) {
return $data;
} else {
return FALSE;
}
}
$test = getPicSite(1);
echo "<h1>Recent Pictures</h1>";
foreach ($test as $key => $value) {
echo " " . $value['title'] . "
<img src=\"" . $value['image'] . "\" height=\"200\"
width=\"200\">
" . $value['pictureID']
. " " . $value['userID'] .
" ";
}
?>
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){
$name=$_POST['name'];
//connect to the database
$conn = loadDatabase();
//-query the database table
try {
$sql="SELECT * FROM picture WHERE title LIKE '%" . $name . "%'";
$stmt = $conn->prepare($sql);
$stmt->execute();
$data = $stmt->fetchAll();
$stmt->closeCursor();
} catch (PDOException $ex) {
echo 'PDO error in model.';
}
}
else{
echo "<p>Please enter a search query</p>";
}
}
}
?>
<form method="post" action="picture.php?go" id="searchform">
<input type="text" name="name">
<input type="submit" name="submit" value="Search">
</form>
</body>
</html>