title: How to insert shopping cart date into database?
body: <p>I'm doing an online Food Ordering System and it has the add to cart function. Below is my cart function code. I would like to insert the data added into the cart by customer into the database to be viewed by the admin or staff to prepare the order. I have no idea how to make it work. I am very new to PHP and this is my first project. Please kindly help me..   </p>
  
  <pre><code>function cart() {
  foreach($_SESSION as $name =&gt; $value){
      if ($value&gt;0) {
          if (substr($name, 0, 5)=='cart_'){
              $id = substr($name, 5, (strlen($name)-5));
              $get = mysql_query('SELECT id, name, price FROM products    WHERE id='.mysql_real_escape_string((int)$id));
              while ($get_row = mysql_fetch_assoc($get)){
                  $sub = $get_row['price']*$value;
                  echo $get_row['name'].' x '.$value.' @ RM '.number_format($get_row['price'], 2).' = RM '.number_format($sub, 2).' &lt;a href="cart.php?remove='.$id.'"&gt;[-]&lt;/a&gt; &lt;a href="cart.php?add='.$id.'"&gt;[+]&lt;/a&gt; &lt;a href="cart.php?delete='.$id.'"&gt;[Delete]&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;';
                  }
              }
              $total += $sub;
          }
  
      } 
      if ($total==0) 
      {
          echo "Your cart is empty.";
      }
      else 
      {
          echo 'Total: RM'.number_format($total, 2);
      }
  
  }
  </code></pre>