I need som help to figure out why my search function doesn't work. I am a beginner in php, dont really have that much knowledge. I saw this code for a search function and tried to use it but it doesn't work.
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){
$name=$_POST['name'];
include("config.php");
$stmt = $connect->prepare('SELECT id, title FROM news WHERE title LIKE '%" . $name . "%'');
$stmt->execute();
while($sa = $stmt->fetch(PDO::FETCH_ASSOC)) {
?>
<p><?php echo $sa['title'];?><br/></p>
<?
}
}
}
}
?>
This is the form:
<div id="search-form" class="pull-right">
<form method="post" action="search.php?go" id="searchform">
<input type="text" name="name" value="" required />
<input type="submit" name="submit" id="submit" value="Sök"/>
</form>