Add Item and stay in current page
<p>I have this code to prosses the ADD TO CART button:</p>

<pre><code>if (isset($_POST['pid'])) {
$pid = $_POST['pid'];
$wasFound = false;
$i = 0;
// If the cart session variable is not set or cart array is empty
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) &lt; 1) {
    // RUN IF THE CART IS EMPTY OR NOT SET
    $_SESSION["cart_array"] = array(0 =&gt; array("item_id" =&gt; $pid, "quantity" =&gt; 1));
} else {
    // RUN IF THE CART HAS AT LEAST ONE ITEM IN IT
    foreach ($_SESSION["cart_array"] as $each_item) {
          $i++;
          while (list($key, $value) = each($each_item)) {
              if ($key == "item_id" &amp;&amp; $value == $pid) {
                  // That item is in cart already so let's adjust its quantity using array_splice()
                  array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" =&gt; $pid, "quantity" =&gt; $each_item['quantity'] + 1)));
                  $wasFound = true;
              } // close if condition
          } // close while loop
       } // close foreach loop
       if ($wasFound == false) {
           array_push($_SESSION["cart_array"], array("item_id" =&gt; $pid, "quantity" =&gt; 1));
       }
}
exit();
}
</code></pre>

<p>And my add button:</p>

<pre><code>&lt;form id="bd_itm1" name="bd_itm1" method="post" action="help_scripts/cart_functions.php"&gt;
      &lt;input type="hidden" name="pid" id="pid" value="'. $id . '" /&gt;
      &lt;input type="submit" name="button" id="button" value="Add to Cart" /&gt;
&lt;/form&gt;
</code></pre>

<p>When I click it it takes me to the cart.php as I tell it to do with my header(location).
But I do not want it to. I want to stay at the same page as my ad button.
Now, if I remove my header(location) it takes me to a blank page. (but still it adds the item to cart)
No errors in my logs. FOR SURE. :)</p>

<p>Many are saying things about ajax and jquery... but I am not that familiar with these!</p>

<p>Thank you</p>

<p>My dynamicList code: (I don't know what's happening but just now it showed me your question)</p>

<pre><code>$sql = mysql_query("SELECT * FROM products WHERE category='body' ORDER BY id ASC");
$productCount = mysql_num_rows($sql);
// count the output amount
if ($productCount &gt; 0) {
        $i=0;
        $dynamicListBody = '&lt;table width: 90%; margin-right: auto; margin-left: auto; color: #00E6AA;&gt;';
        while($row = mysql_fetch_array($sql)){
            $id = $row["id"];
            $product_name = $row["product_name"];
            $details = $row["details"];
            $price = $row["price"];
            $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
        $dynamicListBody .= ($i==0) ? '&lt;tr&gt;':'';
        $dynamicListBody .= '&lt;td width="10%"&gt;
                    &lt;img style="border:#666 1px solid;" src="../stock_photos/' . $id . '.png" height="80px" width="40px" alt="' . $product_name . '" /&gt;
                     &lt;/td&gt;
                     &lt;td width="35%"&gt;
                    &lt;span class=itmttl&gt;' . $product_name . '&lt;/span&gt;
                    &lt;br /&gt;
                    &lt;span class=text&gt;' . $details . '
                    &lt;br /&gt;
                    €' . $price . '&lt;/span&gt;
                    &lt;br /&gt;
                      &lt;form name="bd_itm" id="bd_itm" method="post" action="help_scripts/cart_functions.php"&gt;
                    &lt;input type="hidden" name="pid" id="pid" value="' . $id . '" /&gt;
                    &lt;input type="submit" name="button' . $id . '" id="button' . $id . '" value="Add to Cart" /&gt;
                    &lt;br /&gt;
                    &lt;br /&gt;
                      &lt;/form&gt;
                     &lt;/td&gt;';
        $dynamicListBody .= ($i==1) ? '&lt;/tr&gt;':'';
        $i++;
        ($i==2) ? $i=0:'';
        }
        $dynamicListBody.='&lt;/table&gt;';
        } else {
            $dynamicListBody = "We have no products listed in our store yet";
            }
        mysql_close();
?&gt;
</code></pre>
