title: Undefined variable: searchTerm
body: <p>This works fine except for the first time I open the page and nothing is in the search button. Then I get an error, along with all of the results displayed instead of only when searching:</p>
  <blockquote>
  <p>Undefined variable: searchTerm in C:\xampp\htdocs\index3.php on line 77</p>
  </blockquote>
  <pre><code>&lt;?php
  
  if (isset($_POST['search'])) {
      $searchTerm = $_POST['search'];
  }
              
  $conn = new mysqli(&quot;localhost&quot;, &quot;root&quot;, &quot;&quot;, &quot;Assignment_11&quot;);
  if ($conn-&gt;connect_error) {
      echo 'Connection Faild: '.$conn-&gt;connect_error;
  } else {
      $sql = &quot;select * from Items where name like '%$searchTerm%'&quot;;
  
      $res = $conn-&gt;query($sql);
  
      while ($row = $res-&gt;fetch_assoc()) {
          echo &quot;&lt;br&gt; Name: &quot;. $row[&quot;name&quot;]. &quot;   Type: &quot;. $row[&quot;type&quot;].  &quot;  Brand:  &quot;.  $row[&quot;brand&quot;]. &quot;&lt;br&gt;&quot;;
      }
  }
  </code></pre>