Reputation: 169
I have made a form for searching my site and the php code that im trying to use looks like this
if (isset($_GET['search']))
{
$search = $_GET['search'];
$tsql5 = "SELECT * FROM blog_posts WHERE blog_title LIKE '%:search%'";
$stmt6 = $conn->prepare($tsql5);
$stmt6->execute (array($search));
while($search_result = $stmt6->fetch(PDO::FETCH_BOTH) )
{
echo '$search_result[0]';
and so on...
From all the examples etc that i have found it should be working? when i press the search button i get to mysite.se/index.php?search=searchword
but i get no results when i know im searching for a word that do exists in a blog_title column... am i missing something here?
EDIT: might wanna add that im using microsoft sql server not mysql
Upvotes: 0
Views: 96
Reputation: 23892
You are looking for a something like :search
, not your actual term. (I'd think this actually throw an error about mismatched bound terms to placeholders.) The placeholder needs to be on its own. Also when binding you need to use the bound name in the binding. Try:
$tsql5 = "SELECT * FROM blog_posts WHERE blog_title LIKE :search";
$stmt6 = $conn->prepare($tsql5);
$stmt6->execute (array(':search' => '%' . $search . '%'));
Upvotes: 3