So I came across this issue after I transfered all my files to the server.
PROBLEM: So I have 10 items on my main page. 3 of them in description contains word "chair". When I am trying to search, lets say "chair" on my localhost, browser outputs 3 items out of 10 as it should be. But when I do the same on hosted server it outputs all 10 items but first listed with word "chair".
CODE OF search.php:
$query = $_GET['query'];
$min_length = 3;
$max_length = 300;
if(strlen($query) >= $min_length)
{
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$result = mysqli_query($connecDB,"SELECT * FROM items WHERE title LIKE '%".$query."%' OR description LIKE '%".$query."%'");
if(mysqli_num_rows($result) > 0)
{
$success = "Results for: $query";
while($row = mysqli_fetch_array($result))
{
if (strlen($row['description']) > $max_length)
{
$offset = ($max_length - 3) - strlen($row['description']);
$s = substr($row['description'], 0, strrpos($row['description'], ' ', $offset)) . '...';
} else {
$s = $row['description'];
}
$output = '
<div class="box">
<a href="items/'.$row['id'].'" class="items">
<img src="uploads/thumbs/'.$row['cat_name'].'/'.$row['id'].'/'.$row['image_id'].'.'.$row['item_ext'].'" width="230" height="320">
<div class="art_frame_description">
<h3>'.$row['title'].'</h3>
<h2>'.$s.'</h2>
<h4>£'.$row['price'].'</h4>
</div>
</a>
</div>
';
echo($output);
}
}
else{
$message = "Nothing found for '".$query."'";
}
}
else{
$message = "Your searched word '".$query."' must be longer than ".$min_length. " characters";
}
Does anyone can spot what causes this problem?
EDITED: All sorted, this topic can be closed. Problem was caused by "$query = mysql_real_escape_string($query);" code.