title: Variable not working properly inside mysql query in php
body: <p>I have a table named: "m &amp; m (12-11-15 at 11:11)-Ca:16:20:06-ai" and my sql query is:</p>
  
  <pre><code> $queryac="SELECT * 
             FROM `$actiontable` 
             WHERE (Assignedto LIKE '%$username%' 
                    OR Assignedby='$username')"; 
  </code></pre>
  
  <p>PHP code for the variables is:</p>
  
  <pre><code> $table=$_GET['id'];
  
   $actiontable=$table.'-ai';
   id=m+%26amp%3B+m+%2812-11-15+at+11%3A11%29-Ca%3A16%3A20%3A06
  </code></pre>
  
  <p>(I have tried urldecode($_GET['id']), but it does not work either)</p>
  
  <p>Echoed query is:</p>
  
  <pre><code>SELECT * FROM `m &amp; m (12-11-15 at 11:11)-Ca:16:20:06-ai` WHERE (Assignedto LIKE '%mariummalik22@gmail.com%' OR Assignedby='mariummalik22@gmail.com') 
  </code></pre>
  
  <p>Table name from mysql: m &amp; m (12-11-15 at 11:11)-Ca:16:20:06-ai</p>
  
  <p>Error that I get:</p>
  
  <pre><code> Table 'alsonsrn_actionitems.m &amp; m (12-11-15 at 11:11)-Ca:16:20:06-ai' 
  </code></pre>
  
  <p>(Although the table exists)</p>
  
  <p>When I echo $actiontable, I get m &amp; m (12-11-15 at 11:11)-Ca:16:20:06-ai, which is exactly what my table name is but the query does not work. When I enter the same echoed value manually instead of the variable the query works. What could be the reason of it??</p>
  
  <p><strong>Note: The same query works for the table names that do not consist of "&amp;"</strong></p>