This commit is contained in:
2024-06-19 10:58:42 +02:00
parent 056aceaaaa
commit 5af38630ff
2 changed files with 101 additions and 13 deletions

View File

@@ -97,24 +97,24 @@
} }
} }
if(isset($_GET['search_text'])){ if (isset($_GET['search_text'])) {
$search_text = $_GET['search_text']; $search_text = $_GET['search_text'];
} }
if(!empty($search_text)){ if (!empty($search_text)) {
$con = mysqli_connect($mysql_host,$mysql_user,$mysql_pass); $con = mysqli_connect($mysql_host, $mysql_user, $mysql_pass);
if(mysqli_select_db($con,$mysql_db)){ if (mysqli_select_db($con, $mysql_db)) {
$query = "SELECT `name`, `surname` FROM `globaly_accounts` WHERE `name` LIKE '" . mysqli_real_escape_string($con, $search_text) . "%'";
$query_run = mysqli_query($con, $query);
$query = "SELECT `name`, `surname` FROM `globaly_accounts` WHERE `name` LIKE '". mysqli_real_escape_string($con,$search_text) ."%'"; while ($query_row = mysqli_fetch_assoc($query_run)) {
$query_run = mysqli_query($con,$query); $name = $query_row['name'];
while($query_row = mysqli_fetch_assoc($query_run)){ $surname = $query_row['surname'];
$name = $query_row['name'] ; echo '<a href="search_people.php?name=' . urlencode($name) . '&surname=' . urlencode($surname) . '">' . $name . ' ' . $surname . '</a><br>';
echo $name . ' ' .$query_row['surname'] . '<br>' ;
} }
} }
} }
?> ?>
<body> <body>
@@ -149,7 +149,7 @@
</a> </a>
</li> </li>
</ul> </ul>
<div class="form-container"> <!-- <div class="form-container">
<form class="form-search d-flex align-items-center d-sm-flex justify-content-sm-between mb-0" role="search"> <form class="form-search d-flex align-items-center d-sm-flex justify-content-sm-between mb-0" role="search">
<input id="src-input" class="form-control rounded-0 border-0" type="search" placeholder="Search ..." name="search_text" onkeyup="findmatch();"> <input id="src-input" class="form-control rounded-0 border-0" type="search" placeholder="Search ..." name="search_text" onkeyup="findmatch();">
<button class="btn" type="submit" style="padding-bottom: 0px;padding-top: 0px;"> <button class="btn" type="submit" style="padding-bottom: 0px;padding-top: 0px;">
@@ -158,7 +158,16 @@
</span> </span>
</button> </button>
</form> </form>
</div> -->
<div class="form-container">
<form id="searchForm" class="form-search d-flex align-items-center d-sm-flex justify-content-sm-between mb-0" role="search" onsubmit="return redirectToSearchPeople();">
<input id="src-input" class="form-control rounded-0 border-0" type="search" placeholder="Search ..." name="search_text">
<button class="btn" type="submit" style="padding-bottom: 0px; padding-top: 0px;">
<span class="material-icons pt-1">search</span>
</button>
</form>
</div> </div>
</nav> </nav>
<!-- header --> <!-- header -->
@@ -482,6 +491,14 @@
xmlhttp.send(); xmlhttp.send();
} }
function redirectToSearchPeople() {
const searchText = document.getElementById('src-input').value;
if (searchText.trim() !== "") {
window.location.href = 'search_people.php?search_text=' + encodeURIComponent(searchText);
}
return false; // Prevent the form from submitting the traditional way
}
</script> </script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>

View File

@@ -0,0 +1,71 @@
<?php
require 'php/connect.inc.php';
if (isset($_GET['search_text'])) {
$search_text = $_GET['search_text'];
echo '<h2>Search Results for: ' . htmlspecialchars($search_text) . '</h2>';
$con = mysqli_connect($mysql_host, $mysql_user, $mysql_pass);
if (mysqli_select_db($con, $mysql_db)) {
$query = "SELECT `name`, `surname`, `email`, `birth_day`, `birth_month`, `birth_year` FROM `globaly_accounts` WHERE `name` LIKE '" . mysqli_real_escape_string($con, $search_text) . "%'";
$query_run = mysqli_query($con, $query);
if (mysqli_num_rows($query_run) > 0) {
echo '<table border="1">
<tr>
<th>Name</th>
<th>Surname</th>
<th>Email</th>
<th>Birth Date</th>
</tr>';
while ($query_row = mysqli_fetch_assoc($query_run)) {
$name = $query_row['name'];
$surname = $query_row['surname'];
$email = $query_row['email'];
$birth_date = $query_row['birth_day'] . '.' . $query_row['birth_month'] . '.' . $query_row['birth_year'] . '.';
echo '<tr>
<td>' . htmlspecialchars($name) . '</td>
<td>' . htmlspecialchars($surname) . '</td>
<td>' . htmlspecialchars($email) . '</td>
<td>' . htmlspecialchars($birth_date) . '</td>
</tr>';
}
echo '</table>';
} else {
echo 'No results found.';
}
} else {
echo 'Database selection failed.';
}
mysqli_close($con);
} else {
echo 'No search text provided.';
}
?>
<style>
h2{
color: #15c1cb;
}
table {
width: fit-content;
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
th, td {
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
color: #15c1cb;
}
</style>