I am trying to perform a live search using Ajax,PHP, and MYSQL. The code I have is working. However, the main problem is I can't redirect the user to their profile page once I found the user within the database. I checked the console.log and it has a link to the their profile page. This is the results
https://imgur.com/a/I8tXMvH
HTML
<div class="inner-addon left-addon">
<input class="form-control" type ="text" id ="search" placeholder="Search for employees..." onkeyup="search(this.value)">
<div id ="results"></div>
</div
Ajax Code
function search(value) {
if(value.length == 0)
{
$("#results").html("");
} else {
$.post("employees.php", {search:value}, function(data){
$("#results").html(data);
});
}
}
PHP Code
$search = $_POST['search'];
$query =" SELECT * FROM employees WHERE firstName LIKE '%$search%' OR lastName LIKE '%$search%'";
$query = mysqli_query($connect,$query);
while($row= mysqli_fetch_array($query)){
echo "<div>";
echo $row['firstName']." ".$row['lastName'];
echo "<a href='profile.php?userId=" . $row["id"] . "'>";
echo "</div>";
}
User Profile code
<?php
$userId = ($_GET['userId']);
$query = "SELECT firstName, lastName, middleName, gender, ssn, dob, organization, department, iden, position, salary,health, dental,vision, addressOne, addressTwo, apt, city, _state, zipcode, phone, email FROM employees WHERE id = {$userId}";
$results = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($results)) {
$firstName = $row['firstName'];
$lasttName = $row['lastName'];
$middletName = $row['middleName'];
$gender = $row['gender'];
?>
What I have tried:
I have tried everything and I just can't figure it out.