title: php mysql query with hyphen character
body: <p>I have a query problem with hyphen character.</p>
  
  <pre><code>$user = "test-user";
  $q = @mysql_query("SELECT id FROM table WHERE user='$user'");
  echo mysql_error(); //no error message
  </code></pre>
  
  <p>test-user record is in table but query result coming empty. Also mysql error message is empty. What is wrong?</p>
  
  <hr>
  
  <p>EDIT:
  Thank you for answers. I apologize to everyone. I found the problem and I see now the problem is not in the query. Problem coming form regex.</p>
  
  <pre><code>if (preg_match("/^[a-z0-9]+$/i", $user)) //dash character not in regex
  {
  $q = @mysql_query("SELECT id FROM table WHERE user='$user'");
  }
  </code></pre>
  
  <p>I've corrected the problem as follows:</p>
  
  <pre><code>if (preg_match("/^[a-z0-9\-]+$/i", $user)) //added \- to regex for dash
  {
  $q = @mysql_query("SELECT id FROM table WHERE user='$user'");
  }
  </code></pre>