This question already has an answer here:
- How can I prevent SQL injection in PHP? 28 answers
Anybody pls Convert My below php + mysql search script to php + mysqli or php + Pdo Statement... I don't Know How to do this... Pls help Me... Tnx In Advance...
my form script is
<html>
<head>
<title>search engine</title>
</head>
<body>
<form action = 'ss.php' method ='GET'>
<input type = "text" name = "q">
<input type = "submit" name = "submit" value = "search"
</body>
</html>
And My Search Engine Script is
<?php
$k = $_GET["q"];
$con = mysql_connect("localhost", "root", "");
mysql_select_db("x");
$terms=explode(" ",$k);
$i=0;
$set_limit = ("9");
$subi = "";
foreach ($terms as $each)
{
$i++;
if ($i == 1 )
$subi.= " title LIKE '%$each%' ";
else
$subi.= " AND title LIKE '%$each%' ";
}
$query = "select SQL_CALC_FOUND_ROWS * from table WHERE $subi order by rand() limit $set_limit";
$qry = mysql_query("$query");
$row_object = mysql_query("Select Found_Rows() as rowcount");
$row_object = mysql_fetch_object($row_object);
$actual_row_count = $row_object->rowcount;
$result = $actual_row_count;
?>
Diplaying Results
<?php
if ($result>0)
{
while ($row = mysql_fetch_array($qry)){
$title=$row['title'];
$href=$row['href'];
$img=$row['img'];
echo "<div class=\"col-sm-4\"><div class=\"product-image-wrapper\"><div class=\"single-products\"><div class=\"productinfo text-center\"><img src=\"$img\" alt=\"$title\"><h5>$title</h5><a href=\"$href\" target=_blank </a></div></div></div></div>
";
}
}
else
{
echo "Sorry No Items Found For " .$k;
}
?>
</div>