title: Illegal string offset in echo $_SESSION
body: <p>Recently I trying to study about how to add cart in php and MySQL. Until then I found this useful <a href="http://code.tutsplus.com/tutorials/build-a-shopping-cart-with-php-and-mysql--net-5144" rel="nofollow">website</a>. </p>
  
  <p>However there are a lot of error, that some of it I already know how to correct it.</p>
  
  <p>But I can't understand what this Illegal string offset is about. The error is at line 64 in index.php which is as below.</p>
  
  <p>This is the line 64 error</p>
  
  <pre><code>&lt;p&gt;&lt;?php echo $row['name'] ?&gt; x &lt;?php echo $_SESSION['cart'][$row['id_product']]['quantity'] ?&gt;&lt;/p&gt; 
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/lnaZZ.png" rel="nofollow">Sample Images</a></p>
  
  <pre><code>&lt;?php 
  
  if(isset($_SESSION['cart'])){ 
  
      $sql="SELECT * FROM products WHERE id_product IN ("; 
  
      foreach($_SESSION['cart'] as $id =&gt; $value) { 
          $sql.=$id.","; 
      } 
  
      $sql=substr($sql, 0, -1).") ORDER BY name ASC"; 
      $query=mysqli_query($conn,$sql); 
      while($row=mysqli_fetch_array($query)){ 
  
      ?&gt; 
          &lt;p&gt;&lt;?php echo $row['name'] ?&gt; x &lt;?php echo $_SESSION['cart'][$row['id_product']]['quantity'] ?&gt;&lt;/p&gt; 
      &lt;?php 
  
      } 
  ?&gt;
  </code></pre>