可能重复:
如何防止 PHP 中的 SQL 注入?
如果我在搜索栏上运行下面的查询,为什么我的搜索查询不起作用,它没有返回任何结果,我有一个表格类别,我想从中选择category_title and category_description
然后将其显示为我的结果,我有一个技术类别及其描述,但是当我运行下面的查询时显示没有结果
<?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>\"";
?>