title: Search form with PDO
body: <p><strong>The below code now works but how can I make it so if no results are found it echos a message instead of blank.</strong></p>
  
  <p>I think I've managed to create a search query for my database. Its only a very basic search but it doesn't seem to work for some reason. Any advice would be appreciated im still new to pdo (very new! be kind!). </p>
  
  <p>Also no user submitted data is inserted into the database so I think i can rule out xss assuming its SQL inject free? Which from what I understand PDO is? plus im using a stand alone DB user with no write access.</p>
  
  <p>Have replace data with xxx for security</p>
  
  <p>file is called search.php</p>
  
  <p>*updated to reflect changes suggested
  *2nd update to reflect help provided
  *3rd update </p>
  
  <pre><code>   &lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form name="frmSearch" method="post" action="search.php"&gt;
    &lt;table width="599" border="1"&gt;
      &lt;tr&gt;
        &lt;th&gt;Keyword
        &lt;input name="var1" type="text" id="var1"&gt;
        &lt;input type="submit" value="Search"&gt;&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  &lt;/form&gt;
  &lt;?php
  $nameofdb = 'xxxxxx';
  $dbusername = 'xxxxxxxxxxxxxx';
  $dbpassword = 'xxxxxxxxxxxxx';
  
  
  
  // Connect to MySQL via PDO
  try {
  $dbh = new PDO("mysql:dbname=$nameofdb;host=localhost", $dbusername, $dbpassword);
  $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  } catch (PDOException $e) {
  echo 'Connection failed: ' . $e-&gt;getMessage();
  }
  
  $var1 = str_replace(array('%','_'),'',$_POST['var1']);
  if (!$var1)
  {
      exit('Invalid form value: '.$var1);
  }
  
  
  $query = "SELECT * FROM xxxxx WHERE xxxxxx LIKE :search OR xxxxx LIKE :search";
  $stmt = $dbh-&gt;prepare($query);
  $stmt-&gt;bindValue(':search', '%' . $var1 . '%', PDO::PARAM_INT);
  $stmt-&gt;execute();
  
  /* Fetch all of the remaining rows in the result set */
  print("Fetch all of the remaining rows in the result set:\n");
  
  
   $result = $stmt-&gt;fetchAll();
  
  foreach( $result as $row ) {
      echo $row["id"];
      echo $row["title"];
  }
  
  
  
  
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>