title: MySQL query not working while using php variable in where clause
body: <p>I'm new to PHP and MySQL. I am trying to make a simple search form using which I would want to show the results from the database based on the input text entered in the form.
  My code is like this:</p>
  
  <p>Form.php</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form action="search.php" method="GET" id="form"&gt;
  Name: &lt;input type="text" name="name" &gt;
  Age:&lt;input type="text" name="age"&gt;
  Search&lt;input type="submit" name="submit" id="Search" Value="Search"&gt;
  
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Connect.php</p>
  
  <pre><code>  &lt;?php
    $connect = mysql_connect('localhost','$user','$password'); 
  
    if(!$connect){
  die('Could not connect'.mysql_error() );  
    }
  
    $db_selected = mysql_select_db('test');  
  
    if(!$db_selected){
  die('wrong'.mysql_error() );
    }
  
    ?&gt;
  </code></pre>
  
  <p>Search.php</p>
  
  <pre><code> &lt;?php
    include("includes/connect.php");
  
    $name=$_GET['name'];
  
  
    echo $name;
  
    $query = "SELECT * FROM `cats` WHERE name='\$name'";
    $results= mysql_query($query);
  
  
    if (!empty($results)){
  echo "query successful" ;
  exit;
     }
    $row=mysql_fetch_assoc($results);
    echo "Age:".$row['age'];
    echo "Name:".$row['name'];
   ?&gt;
  </code></pre>
  
  <p>The <code>echo $names</code> ouputs the result correctly and so does <code>echo "query successful"</code>.
  However the </p>
  
  <pre><code>echo "Age:".$row['age']; 
  echo "Name:".$row['name'];
  </code></pre>
  
  <p>only echo's the string part and the query does not seem to fetch any results.</p>
  
  <p>I tried changing the <code>mysql_fetch_asso</code>c to <code>mysql_fetch_array</code>, but it does not do anything either. Could anyone tell me what am i doing wrong here. My DB table has two columns and two rows.</p>