title: PHP variable and MySQL LIKE query is not working
body: <p>I have the following code:</p>
  
  <pre><code>$surname=$_POST['surname'];
  $sql2="SELECT * FROM andriana WHERE surname LIKE '$surname%'";
  if (!mysql_query($sql2,$con)){
  die('Error: ' . mysql_error());
  }
  $result2 = mysql_query($sql2);
  
  echo "&lt;table&gt;";
  while ($data = mysql_fetch_array($result2)) {
      echo "&lt;tr&gt;";
      echo "&lt;td style='width:100px;height:40px'&gt;".$data['name']."&lt;/td&gt;";
      echo "&lt;td style='width:100px;height:40px'&gt;".$data['surname']."&lt;/td&gt;";
      echo "&lt;td style='width:100px;height:40px'&gt;".$data['checkIN']."&lt;/td&gt;";
      echo "&lt;/tr&gt;";
  }
  echo "&lt;/table&gt;&lt;br&gt;&lt;br&gt;";
  </code></pre>
  
  <p>and let's say the following records in my table:</p>
  
  <pre><code>- Surname -
  Greyjoy
  Lannister
  Stark
  </code></pre>
  
  <p>What happens is that if I won't type the full surname, it throws error that that surname doesn't exist. As a result the LIKE "%" is not working.</p>
  
  <p>I have tried LIKE '".$surname."$' or LIKE '{$surname}%', but nothing happens too.</p>
  
  <p>I searched here in Stack a lot, and it seems that the above tryouts should be working. </p>
  
  <p>What am I missing?</p>
  
  <ul>
  <li>post-comments-editing - </li>
  </ul>
  
  <p>To be more understood, I am sure that the variable contains the actual surname as a string, because if I type the whole surname, my application works normally. However, if I type the first 3 letters (or 4...) the application returns my homemade message that the surname typed is wrong.</p>
  
  <p>Also, to go over the problem with case sensitive, my testing is done with a surname which has only small characters.</p>
  
  <p>Thank you all for your effort, still havinf the issue!</p>