title: MySQL query search includes results from wrong column
body: <p>I've got a search bar that is returning proper results, except that it is including results from a column I don't want to be searched.</p>
  <p>MySQL query (file name <code>search2.php</code>):</p>
  <pre class="lang-php prettyprint-override"><code>if ($_SERVER[&quot;REQUEST_METHOD&quot;] === &quot;POST&quot;) {
    $submitted_search = $_POST['search'];
  }
  
  $safe_search = '%' . $submitted_search . '%'; //I know it's not 'safe' yet-bound below!
  
  $sqlSearch = &quot;
  SELECT tbl.title
       , tbl.artists
       , tbl.date_starting
       , tbl.date_ending
       , tbl.opening_date
       , tbl.opening_time
       , tbl.category
       , tbl.cost
       , tbl.place_decode_strip
       , tbl.title_decode_strip
       , tbl.artists_decode_strip
       , place.site
       , place.addr
       , place.hours
       , place.web
       , place.admis
    FROM tbl
   JOIN place
      ON tbl.place = place.site
   WHERE CONCAT_WS(' || ', tbl.date_ending, tbl.opening_date, tbl.place_decode_strip, 
  tbl.title_decode_strip, tbl.artists_decode_strip,
  place.aka)
  LIKE ?
   ORDER 
      BY date_ending DESC
  &quot;;
  
  $stmt = $conn-&gt;prepare($sqlSearch);
  $stmt-&gt;bind_param(&quot;s&quot;, $safe_search);
  $stmt-&gt;execute();
  $data = $stmt-&gt;get_result();
  
  $searchResultsNum = mysqli_num_rows($data);
  
  if ($searchResultsNum === 0) {
    echo &quot;&lt;h3&gt;There are no results matching your search.&lt;/h3&gt;&quot;;
  } elseif ($searchResultsNum === 1) {
    echo &quot;&lt;h3&gt;There is 1 result matching &amp;ldquo;&lt;i&gt;&quot; . $submitted_search . &quot;&lt;/i&gt;&amp;#8239;&amp;rdquo;.&lt;/h3&gt;&quot;;
  } else {
    echo &quot;&lt;h3&gt;There are &quot; . $searchResultsNum . &quot; results matching &amp;ldquo;&lt;i&gt;&quot; . $submitted_search . &quot;&lt;/i&gt;&amp;#8239;&amp;rdquo;.&lt;/h3&gt;&quot;;
  }
  
  if ($searchResultsNum &gt; 0) {
    // data of each row
    while ($searchRow = $data-&gt;fetch_assoc()) {
      $date = strtotime($searchRow[&quot;opening_date&quot;]);
      $sdate = strtotime($searchRow[&quot;date_starting&quot;]);
      $edate = strtotime($searchRow[&quot;date_ending&quot;]); ?&gt;
      &lt;section class=&quot;entry&quot;&gt;
        &lt;article class=&quot;site-info&quot;&gt;
          &lt;p class=&quot;site&quot;&gt;&lt;?php $web = $searchRow[&quot;web&quot;];
                          echo &quot;&lt;a href='$web' target='_blank' rel='noreferrer'&gt;&quot; . $searchRow[&quot;site&quot;]; ?&gt;&lt;/a&gt;
          &lt;/p&gt;
          &lt;p class=&quot;site-add&quot;&gt;&lt;?php echo $searchRow[&quot;addr&quot;]; ?&gt;&lt;/p&gt;
          &lt;p class=&quot;site-hrs&quot;&gt;&lt;?php echo $searchRow[&quot;hours&quot;]; ?&gt;&lt;/p&gt;
        &lt;/article&gt;
  
        &lt;article class=&quot;event-info&quot;&gt;
          &lt;p class=&quot;title&quot;&gt;&lt;?php echo $searchRow[&quot;title&quot;]; ?&gt;&lt;/p&gt;
          &lt;p class=&quot;artists&quot;&gt;&lt;?php echo $searchRow[&quot;artists&quot;]; ?&gt;&lt;/p&gt;
          &lt;?php if ($searchRow[&quot;date_starting&quot;] != $searchRow[&quot;date_ending&quot;]) {
          ?&gt;&lt;p&gt;&lt;?php
                echo date(&quot;F j&quot;, $sdate) . &quot; – &quot;;
                echo date(&quot;F j, Y&quot;, $edate); ?&gt;&lt;/p&gt;
            &lt;p&gt;&lt;?php
              }
              echo $searchRow[&quot;category&quot;] . &quot;: &quot;;
              echo date(&quot;F j&quot;, $date) . &quot;, &quot;;
              echo $searchRow[&quot;opening_time&quot;]; ?&gt;&lt;/p&gt;
            &lt;?php if ($searchRow[&quot;cost&quot;] !== null) { ?&gt;
              &lt;p&gt;&lt;?php echo $searchRow[&quot;cost&quot;]; ?&gt;&lt;/p&gt;
            &lt;?php } ?&gt;
        &lt;/article&gt;
      &lt;/section&gt;
  &lt;?php }
  }
  ?&gt;
  </code></pre>
  <p>JavaScript:</p>
  <pre class="lang-js prettyprint-override"><code>const searchButton = document.getElementById('search-btn');
  searchButton.addEventListener(&quot;click&quot;, stopRedirect);
  
  function submitSearch() {
    const searchInput = document.getElementById('searchInput').value;
    //  const searchResultId = document.getElementById('search-results');
    if (!searchInput) {
      document.getElementById('search-results').innerHTML = &quot;Please enter search term.&quot;
    } else if (searchInput == ' ') {
      document.getElementById('search-results').innerHTML = &quot;Please enter a valid search term.&quot;
    } else if (searchInput == '%') {
      document.getElementById('search-results').innerHTML = &quot;Please enter a valid search term.&quot;
    } else {
      var formData = new FormData();
      formData.append('search', searchInput);
  
      var xhttp = new XMLHttpRequest();
      xhttp.open(&quot;POST&quot;, &quot;../phpScripts/search2.php&quot;, true);
  
      xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 &amp;&amp; xhttp.status == 200) {
          const response_data = xhttp.response;
          document.getElementById('search-results').innerHTML = response_data; //this.response
        }
      }
    }
  
    xhttp.send(formData);
  }
  
  function stopRedirect(e) {
    e.preventDefault();
  }
  </code></pre>
  <p>HTML search form:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;aside class=&quot;search-field&quot;&gt;
    &lt;form class=&quot;search-form&quot; id=&quot;search-form&quot; action=&quot;/phpScripts/search2.php&quot; method=&quot;POST&quot; role=&quot;search&quot;&gt;
      &lt;input type=&quot;search&quot; name=&quot;search&quot; placeholder=&quot;Search all events&quot; 
        id=&quot;searchInput&quot; aria-label=&quot;Search through site content&quot; /&gt;
      &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; id=&quot;search-btn&quot; onclick=&quot;submitSearch()&quot; /&gt;
    &lt;/form&gt;
  &lt;/aside&gt;
  </code></pre>
  <p>When I search for <code>&lt;</code> I get correct results from <code>event_tbl.title</code> (that is, it includes titles with HTML tags) but I don't want results from that column. I only want results from the decoded and stripped columns, <code>tbl.title_decode_strip</code> in this case.</p>
  <p>Why is the query returning results from <code>tbl.title</code>? How can I limit the query to not include search (WHEN) results from <code>tbl.title</code>? I need to include <code>tbl.title</code> in the query because that is part of the HTML that gets returned in the AJAX. <code>tbl.title</code> isn't included in the <code>WHEN</code> part of the query, so I don't know why it is included in the results.</p>