I have two pages, perfil.php
and user.php
, profile.php opens when I log in with my username and enter my profile and user.php is when I search by username and takes me to the profile of the searched user.
How can I prevent the search for the same logged in user from taking me to user.php
, instead of going toperfil.php
I do the search through an auto-complete that shows me the users according to what I write.
PHP
<?php
include("conexion.php");
if(isset($_POST['query']))
{
$output = '';
$query = "SELECT * FROM personas WHERE nombre LIKE '%".
$_POST['query']."%'";
$result = mysqli_query($conn, $query);
$output = '<ul class="list-unstyled">';
if(mysqli_num_rows($result) > 0 )
{
while($row = mysqli_fetch_array($result))
{
$output .= '<li><img style="border-radius:50%;" id="pic-search"
src="'.$row['Fotos'].'" width ="100px" height="100px"></img><a
href="user.php?Id='.$row['Id'].'">'.$row['nombre'].'
'.$row['apellido'].'</a></li>';
}
}
else
{
$output .= '<li>Not found</li>';
}
$output .= '</ul>';
echo $output;
}
?>
I assume you save the logged in user a$_SESSION['id_usario']
.According to the OP's comment, it has the user's id in the
$my_id
saved variable.Then you search your query for everyone except the logged in user...
Side note :
Please use prepared statements to avoid SQL Injections .