title: Cart's update on subpages
body: <p>My cart doesn't want to update on subpages, even though I basically copied the same code from index.php (including the script). I checkec twice and everything is linked correctly, and it should be working properly. I have no idea what is going on :(( Plz someone help.</p>
  <p>This is the error I get:<br />
  <code>$ is not defined</code><br />
  This is my code on subpages. Excuse for the length:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;&gt;
      &lt;title&gt; Caroline | Homemade Candles&lt;/title&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;
      &lt;link rel=&quot;preconnect&quot; href=&quot;https://fonts.gstatic.com&quot;&gt; 
  &lt;link href=&quot;https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&amp;display=swap&quot; rel=&quot;stylesheet&quot;&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;https://stackpath.boothstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css&quot;&gt;
  &lt;link rel=&quot;shortcut icon&quot; href=&quot;favico.png&quot; /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class=&quot;container&quot;&gt;
          &lt;div class=&quot;darmowadostawa&quot;&gt;
      &lt;p&gt;Darmowa dostawa od 100zł!&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class=&quot;emailugory&quot;&gt;
      &lt;a href=&quot;mailto:#&quot;&gt;E-mail:xxx&lt;/a&gt;
      &lt;a href=&quot;tel:#&quot;&gt;Numer telefonu:xxx-xxx-xxx&lt;/a&gt;
  &lt;/div&gt;
  
          
          
          
          &lt;nav&gt;
  
              &lt;ul id=&quot;MenuItems&quot; &gt;
  &lt;li class=&quot;logo&quot;&gt;&lt;a href=&quot;index.php&quot;&gt;&lt;img src=&quot;logooficjalne.png&quot; class=&quot;carolinepng&quot;&gt;&lt;/a&gt;&lt;/li&gt;
              &lt;li style=&quot;margin-left: 400px;&quot;&gt;&lt;a href=&quot;swieceswiateczne.html&quot;&gt;Boże Narodzenie&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href=&quot;jesien.php&quot;&gt;Jesień - Zima&lt;/a&gt;&lt;/li&gt;     
                  &lt;li&gt;&lt;a href=&quot;zapachy.php&quot;&gt;Dodatkowe zapachy&lt;/a&gt;
              &lt;/li&gt;
              &lt;li&gt;&lt;a href=&quot;blog.html&quot;&gt;Blog&lt;/a&gt;&lt;/li&gt;
  
  
  
  
   &lt;li class=&quot;nav-item&quot;&gt; &lt;a href=&quot;cart.php&quot;&gt; &lt;i class=&quot;fab fa-opencart&quot;&gt;&lt;img src=&quot;cart.png&quot; width=&quot;20px&quot; margin-top=&quot;0px;&quot;&gt;&lt;/i&gt;&lt;span id=&quot;cart-item&quot; class=&quot;badge badge-danger&quot;&gt;0&lt;/span&gt; &lt;/a&gt; &lt;/li&gt;
              &lt;/ul&gt;
              &lt;/nav&gt;
              
  
      
          &lt;img src=&quot;menu.png&quot; class=&quot;menu-icon&quot; onclick=&quot;menutoggle()&quot;&gt;
  &lt;/div&gt;
      &lt;/div&gt;
    &lt;div class=&quot;container&quot;&gt;
      
   &lt;h2 class=&quot;title&quot;&gt;Produkty&lt;/h2&gt;
      &lt;div class=&quot;row mt-2&quot;&gt;
          &lt;?php
          include 'config.php';
          $stmt = $conn-&gt;prepare(&quot;SELECT * FROM stronaproduktyphp&quot;);
          $stmt-&gt;execute();
          $result = $stmt-&gt;get_result();
          while($row = $result-&gt;fetch_assoc()):
          ?&gt;
          &lt;div class=&quot;col-lg-3&quot;&gt;
                  &lt;div class=&quot;card-deck&quot;&gt;
                      &lt;div class=&quot;card p-2 border-secondary mb-2&quot;&gt;
                      &lt;a href=&quot;&lt;?= $row['id'] ?&gt;.php&quot;&gt;&lt;img style=&quot;margin-left:30px;&quot; src=&quot;&lt;?= $row['zdjecie_produktu'] ?&gt;&quot; class=&quot;card-img-top&quot; height=&quot;250&quot;&gt;&lt;/a&gt;
                          &lt;div style=&quot;margin-left: 30px; margin-right: 30px;&quot; class=&quot;card-body p-1&quot;&gt;
                              &lt;h4 class=&quot;card-title text-center text-info&quot;&gt;&lt;?= $row['nazwa_produktu'] ?&gt; &lt;/h4&gt;
                              &lt;h5 style=&quot;color:#fff;&quot; class=&quot;card-text text-center text-danger&quot;&gt;&lt;?= number_format($row['cena_produktu'],2) ?&gt;zł&lt;/h5&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;card-footer p-1&quot;&gt;
                              &lt;form action=&quot;&quot; class=&quot;form-submit&quot;&gt;
                                  &lt;input type=&quot;hidden&quot; class=&quot;pid&quot; value=&quot;&lt;?= $row['id'] ?&gt;&quot;&gt;
                                  &lt;input type=&quot;hidden&quot; class=&quot;pname&quot; value=&quot;&lt;?= $row['nazwa_produktu'] ?&gt;&quot;&gt;
                                  &lt;input type=&quot;hidden&quot; class=&quot;pprice&quot; value=&quot;&lt;?= $row['cena_produktu'] ?&gt;&quot;&gt;
                                  &lt;input type=&quot;hidden&quot; class=&quot;pimage&quot; value=&quot;&lt;?= $row['zdjecie_produktu'] ?&gt;&quot;&gt;
                                  &lt;input type=&quot;hidden&quot; class=&quot;pcode&quot; value=&quot;&lt;?= $row['kod_produktu'] ?&gt;&quot;&gt;
                                  &lt;button style=&quot;margin-left:300px;&quot; class=&quot;btn btn-info btn-block addItemBtn&quot;&gt;&lt;img src=&quot;cart.png&quot; width=&quot;20px;&quot;&gt;&lt;/button&gt;
                                  &lt;style&gt;
        .btn:hover {
          background: #F5E595;
        }
      &lt;/style&gt;
                              &lt;/form&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;          
   &lt;/div&gt;
  &lt;?php endwhile; ?&gt;
  
   &lt;/div&gt;
  &lt;/div&gt;
      
          &lt;footer&gt;
              &lt;div class=&quot;column&quot;&gt;
              &lt;ul class=&quot;footer-links-main&quot;&gt;
                  &lt;li&gt;&lt;a href=&quot;onas.html&quot;&gt;O nas&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href=&quot;produkty.html&quot;&gt;Produkty&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href=&quot;polityka.html&quot;&gt;Regulamin&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href=&quot;contact.html&quot;&gt;Kontakt&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href=&quot;faq.html&quot;&gt;FAQ&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
              &lt;div class=&quot;footer-sm&quot;&gt; 
                  &lt;div class=&quot;column2&quot;&gt;
                  &lt;h3 class=&quot;kontakth3&quot;&gt;Kontakt&lt;/h3&gt;
                  &lt;p class=&quot;kontaktp&quot;&gt;Adres e-mail:xxx&lt;/p&gt;
                  &lt;p class=&quot;kontaktp&quot;&gt;Numer telefonu:xxx&lt;/p&gt;
                          &lt;/div&gt;
          &lt;/div&gt;
          &lt;/footer&gt;
  &lt;script&gt;
          var MenuItems = document.getElementById(&quot;MenuItems&quot;);
  
          MenuItems.style.maxHeight = &quot;0px&quot;;
  
          function menutoggle(){
              if (MenuItems.style.maxHeight == &quot;0px&quot;)
              {
                  MenuItems.style.maxHeight = &quot;200px&quot;;
              }
              else
              {
                  MenuItems.style.maxHeight = &quot;0px&quot;;
              }
          }
      &lt;/script&gt;
      &lt;script src=&quot;main.js&quot;&gt;&lt;/script&gt;
      &lt;script type=&quot;text/javascript&quot;&gt;
      $(document).ready(function(){
          $(&quot;.addItemBtn&quot;).click(function(e){
                  e.preventDefault(); 
                  var $form = $(this).closest(&quot;.form-submit&quot;);
                  var pid = $form.find(&quot;.pid&quot;).val();
                  var pname = $form.find(&quot;.pname&quot;).val();
                  var pprice = $form.find(&quot;.pprice&quot;).val();   
                  var pimage = $form.find(&quot;.pimage&quot;).val();
                  var pcode = $form.find(&quot;.pcode&quot;).val();
  
                  $.ajax({
                      url: 'action.php',
                      method: 'post',
                      data: {pid:pid,pname:pname,pprice:pprice,pimage:pimage,pcode:pcode},
                      success:function(response){
                          $(&quot;#message&quot;).html(response);
                                      load_cart_item_number();
  
  
                      }
                  });
              });
              load_cart_item_number();
  
  
          function load_cart_item_number(){
              $.ajax({
                  url: 'action.php',
                  method: 'get',
                  data: {cartItem:&quot;cart_item&quot;},
                  success: function(response){
                      $(&quot;#cart-item&quot;).html(response);
                  }
              });
          }
      });
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>