title: getting MYSQL error code while trying to get json data from database
body: <p>I am trying to get an AJAX search working, i am very close to this. Here is the php that i am using.</p>
  
  <pre><code>&lt;?php
  $servername = "localhost";
  $username = "root";
  $password = "";
  $dbname = "Products";
  
  try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
    $searchValue = $_GET['search'];
  
    if(isset($searchValue) &amp;&amp; $searchValue != ''){
      $search = addslashes($searchValue);
      $statement = $conn-&gt;prepare("SELECT ProductName FROM Product WHERE ProductName LIKE('" . $search . "%') ORDER BY ProductName");
      $statement-&gt;execute();
  
  
      $all = $statement-&gt;fetchAll(PDO::FETCH_ASSOC);
      for($i=0; $i&lt;count($all);$i++){
        echo json_encode($all[$i]).ProductName;
      }
    }
  
  }
  catch(PDOException $e)
  {
    echo "Error: " . $e-&gt;getMessage();
  }
  
  $conn = null;
  ?&gt;
  </code></pre>
  
  <p>The responseText i get is this:</p>
  
  <blockquote>
    <p>Notice: Use of undefined constant ProductName - assumed 'ProductName'
    in F:\xampp\htdocs\searchSuggest.php on line 23</p>
    
    <p>{"ProductName":"iMac"}ProductName</p>
    
    <p>Notice: Use of undefined constant ProductName - assumed 'ProductName'
    in F:\xampp\htdocs\searchSuggest.php on line 23</p>
  </blockquote>
  
  <p>The only thing i want to display is the "iMac" part of the json object</p>