title: PHP MySQL query returning NULL
body: <p>I have a MySQL table that looks like this:</p>
  
  <pre><code>index  |  tag  |  posts
  -------------------------
    1    | cats  |   9,10
    2    | a cat |   9,10
    3    | kitty |   9,10
    4    | meow  |   9,10
  </code></pre>
  
  <p>I am trying to just return the row that matches a search query.
  I passed the search parameter using a simple <code>?search=cats</code>.
  This is the PHP that I'm using:</p>
  
  <pre><code>$search = $_GET['search'];
  $query  = mysql_query("SELECT * FROM tags WHERE tag = '$search'");
  echo(mysql_num_rows($query));
  $result = mysql_fetch_array($query);
  $print  = $result['posts'];
  echo($print);
  </code></pre>
  
  <p>However the <code>mysql_num_rows($query)</code> prints 0 and the <code>$print</code> returns NULL. I can check it with <code>($print == "")</code>, it evaluates to TRUE and <code>mysql_num_rows($query)</code> returns 4.
  I tried setting the search query to something that wasn't in the table and it retuned FALSE as expected. I also tried removing the <code>WHERE tag = '$search'</code> and it returns the table like it should.</p>
  
  <p>Is there something I'm overlooking?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Took everyone's advice and the code I'm using now is:</p>
  
  <pre><code>$search = mysql_real_escape_string($_GET['search']);
  var_dump($search); //prints   string(4) "cats"   just like it should
  $queryText = "SELECT * FROM tags WHERE tag = '%".$search."%'";
  echo($queryText); //SELECT * FROM tags WHERE tag = '%cats%'
  $query  = mysql_query($queryText) or die(mysql_error()); //no error
  $rows   = mysql_num_rows($query); //this returns 0 and I know it should match 1 row
  echo('rows: '.$rows);
  $result = mysql_fetch_array($query);
  $print  = $result['posts'];
  echo($print); //empty
  </code></pre>
  
  <p>Still have the same problem. The <code>mysql_query</code> is retuning NULL instead of the row or FALSE if it doesn't match.</p>
  
  <p><em>(in the future I will use the <code>mysqli</code> API, but I would like to finnish this project in <code>mysql</code>. thanks for your suggestions and advice)</em></p>