title: How to retrieve MySQL database data using a php search bar
body: <p>I have created a search bar using PHP and I want to retrieve the data I have in my MySQL database.</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>&lt;?php
  
  $button = $_GET ['submit'];
  $search = $_GET ['search'];
  
  if(!$button)
  echo "You searched for '&lt;b&gt;$search&lt;/b&gt;' &lt;hr size='1'&lt;/br&gt;";
  $con=mysqli_connect("localhost", "root", "root", "PM_DB");
  
  if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  
  $search_exploded = explode (" ", $search);
  
  foreach($search_exploded as $search_each)
  {
  $x++;
  if($x==1)
  $construct .="keywords LIKE '%$search_each%'";
  else
  $construct .="AND keywords LIKE '%$search_each%'";
  
  }
  
  $construct ="SELECT * FROM Leads WHERE $construct";
  $run = mysqli_query($construct);
  
  $foundnum = mysqli_num_rows($run);
  
  if ($foundnum==0)
  echo "There are no results for &lt;b&gt;'$search'&lt;/b&gt;. Please check your spelling.";
  else
  {
  echo "$foundnum results found !&lt;p&gt;";
  
  while($runrows = mysqli_fetch_assoc($run))
  {
  $Company = $runrows['Clients'];
  
  echo "&lt;a href='$Company'&gt;&lt;b&gt;Company&lt;/b&gt;&lt;/a&gt;&lt;br&gt;";
  
  }
  }
  
  ?&gt;
  </code></pre>
  
  <p>Every time I click search it only returns the error message. What am I missing out? Any suggestions will be highly appreciated! Thanks - Tijger.</p>