Possible Duplicate:
How to prevent SQL injection in PHP?
why isn't my search query not working if i run the query below on my search bar its returning no results, i have a table categories and from it i jut want to select the category_title and category_description
then display it as my result,i have a technology category and its description but when i run the query below is showing that there are no results
<?php
$k = $_GET['k'];
$terms = explode(" ", $k);
echo $terms;
foreach ($terms as $each) {
$i = "";
$i++;
$query = "";
if ($i == 1)
$query .= "keywords like '%$each%'";
else
$query .= "OR keywords like '%$each%'";
}
$connect = mysql_connect("localhost", "root", "limo");
if (!$connect) {
die(mysql_error());
}
//Selecting database
$select_db = mysql_select_db("forumShh", $connect);
if (!$select_db) {
die(mysql_error());
}
$query = mysql_query($query);
$numrows = mysql_num_rows($query);
if ($numrows > 0) {
while ($row = mysql_fetch_assoc($query)) {
$id = $row['id'];
$title = $row['category_title'];
$description = $row['category_description'];
echo "<a href='view_category.php?cid=" . $id . "' class='cat_links'>" . $title . " - <font size='-1'>" . $description . "</font></a>";
}
} else
echo "No results found for \"<b>$k</b>\"";
?>