-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathanimalQuery.php
More file actions
41 lines (29 loc) · 974 Bytes
/
animalQuery.php
File metadata and controls
41 lines (29 loc) · 974 Bytes
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
error_reporting(E_ALL);
ini_set('display_errors', 'On');
session_start();
include 'password.php';
$mysqli = new mysqli("oniddb.cws.oregonstate.edu", "hansejod-db", $password, "hansejod-db");
if(session_status() == PHP_SESSION_ACTIVE){
$animal = $_POST['animal'];
if (!($stmt = $mysqli->prepare("SELECT * FROM furryFriends WHERE animal='$animal'"))) {
echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error . "<br>";
}
if (!($stmt->execute())) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt.error;
}
else {
$stmt->execute();
}
$res = $stmt->get_result();
$row = $res->fetch_assoc();
//Create an array of all results
$allResults = array();
while ($row) {
array_push($allResults, $row);
$row = $res->fetch_assoc();
}
}
$stmt->close();
echo json_encode($allResults);
?>