-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearchsystem.php
More file actions
35 lines (27 loc) · 816 Bytes
/
Copy pathsearchsystem.php
File metadata and controls
35 lines (27 loc) · 816 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
<?php
$servername = "localhost:3306";
$username = "root";
$password = "monish777";
$dbname = "COSMIC";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get the search parameter from the URL
$name = isset($_GET['name']) ? $_GET['name'] : '';
$name = $conn->real_escape_string($name);
// Query the StarSystems table based on partial match
$sql = "SELECT * FROM StarSystems WHERE Name LIKE '%$name%'";
$result = $conn->query($sql);
$results = [];
if ($result && $result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$results[] = $row;
}
}
// Return the result as JSON
echo json_encode($results);
$conn->close();
?>