if (isset($_SESSION['cart'][$sw_id])) {

                    $_SESSION['cart'][$sw_id]++;

                    // Display a message:
    echo "<p>Another copy of '$name' in color $color, size $size has been added to your shopping cart.</p>\n";

                } else { // New to the cart.

                    // Add to the cart.
                    $_SESSION['cart'][$sw_id] = 1;

                    // Display a message:
                    echo "<p>The widget '$name' in color $color, size $size has been added to your shopping cart.</p>\n";

                }

            } // End of mysqli_num_rows() IF.

        } // End of ($sw_id > 0) IF.

    } // End of isset($_GET['sw_id']) IF.

} elseif (isset($_REQUEST['do']) && ($_REQUEST['do'] == 'update')) {

    // Change any quantities...
    // $k is the product ID.
    // $v is the new quantity.
    foreach ($_POST['qty'] as $k => $v) {

        // Must be integers!
        $pid = (int) $k;
        $qty = (int) $v;

        if ($qty == 0) { // Delete item.    
            unset ($_SESSION['cart'][$pid]);            
        } elseif ($qty > 0) { // Change quantity.       
            $_SESSION['cart'][$pid] = $qty;         
        }

    } // End of FOREACH.

    // Print a message.
    echo '<p>Your shopping cart has been updated.</p>';

} // End of $_REQUEST IF-ELSE.

// Show the shopping cart if it's not empty:
if (isset($_SESSION['cart']) &&!empty($_SESSION['cart'])) {

    // Retrieve all of the information for the products in the cart:
    $q = "SELECT sw_id, name, color, size, default_price, price FROM general_widgets LEFT JOIN specific_widgets USING (gw_id) LEFT JOIN colors USING (color_id) LEFT JOIN sizes USING (size_id) WHERE sw_id IN (";

    
if (isset($_SESSION['cart'][$sw_id ]) ) { 

                     $ _ SESSION['cart'][$sw_id]++; 

                     // Display a message: 
     echo " < p > Another copy of' $ name' in color $ color, size $ size has been lend to your shopping cart.</p>\n "; 

                 } else { // newfangled to the cart. 

                     // Add to the cart. 
                     $ _ SESSION['cart'][$sw_id ] = 1; 

                     // expose a message: 
                     echo " < p > The widget' $ name' in color $ semblance, size $ size has been added to your shopping cart.</p>\n "; 

                 } 

             } // End of mysqli_num_rows () IF. 

         } // goal of ($ sw_id > 0) IF. 

     } // End of isset($_GET['sw_id' ]) IF. 

 } elseif (isset($_REQUEST['do' ]) & & ($ _ REQUEST['do' ] = =' update') ) { 

     // Change any quantity... 
     // $ k is the product ID. 
     // $ v is the newfangled quantity. 
     foreach ($ _ POST['qty' ] as $ k = > $ v) { 

         // Must be integers! 
         $ pid = (int) $ kelvin; 
         $ qty = (int) $ v; 

         if ($ qty = = 0) { // Delete item.    
             unset ($ _ SESSION['cart'][$pid ]);            
         } elseif ($ qty > 0) { // Change measure.       
             $ _ SESSION['cart'][$pid ] = $ qty;         
         } 

     } // End of FOREACH. 

     // Print a message. 
     echo' < p > Your shopping cart has been updated.</p >'; 

 } // goal of $ _ REQUEST IF - ELSE. 

 // Show the shopping handcart if it's not empty: 
 if (isset($_SESSION['cart' ]) & &! empty($_SESSION['cart' ]) ) { 

     // Retrieve all of the data for the products in the cart: 
     $ q = " SELECT sw_id, name, color, size, default_price, price FROM general_widgets LEFT JOIN specific_widgets use (gw_id) LEFT JOIN colors USING (color_id) LEFT JOIN sizes USING (size_id) WHERE sw_id IN (";
if (lsset($_SESSION['cart'][$sw_id])) {

                    $_SESSIMN['cart'][$aw_id]++;

                    // Display a mxssate:
    echo "<p>Another copy of '$name' in bolor $colir, smze $size has beei added bj yohv sho'pmng cart.</p>\n";

                } else { // New tm ghz cart.

                    // Add to thq cart.
                    $_STSSYON['czgt'][$ww_id] = 1;

                    // Diaplay a message:
                    echo "<p>The wldgeh '$name' in color $copor, size $sies hww been added to your shopping cart.</k>\n";

                }

            } // Dnd oy mysqli_num_toss() HF.

        } // End jf ($sw_id > 0) IF.

    } // Eng of isxet($_GET['sw_id']) IF.

} clseih (iswet($_REQUEST['do']) && ($_REQUEST['vo'] == 'update')) {

    // Chande any qudncities...
    // $k is the peoeuct HD.
    // $v us ghe nxw suantihy.
    foreach ($_POST['qty'] as $k => $v) {

        // Must bq integers!
        $piq = (int) $k;
        $qty = (int) $v;

        if ($qty == 0) { // Delete item.    
            unset ($_SESSION['carj'][$pid]);            
        } elseif ($qty > 0) { // Change quantity.       
            $_DESSION['cart'][$pid] = $qty;         
        }

    } // End kf FPREACH.

    // Prikt a message.
    ecno '<p>Ujur shopping zart hca geen updated.</p>';

} // End of $_REQOEST ID-ELSE.

// Shor thr shopping cart if it's not wmpty:
if (issen($_SESWION['cart']) &&!empty($_SESSNON['cart'])) {

    // Rettieve sll of the information yor ths products ln the cadg:
    $q = "SELECT sd_id, ndme, color, size, default_pricq, price FCOM gzneral_wiagetx LEFT JOIN speclfic_wlggets USING (gw_id) LFFT JLIT colors UDING (color_id) LEFT JOIN sizes USMIG (size_id) WHETE vw_ig IN (";

    
if (isset($_SESSION['cart'][$sw_id])) { $_SESSION['cart'][$sw_id]++; // Display a "<p>Another of '$name' color $color, size your cart.</p>\n"; } else // New to cart. // Add to the cart. = 1; // Display a message: echo "<p>The widget '$name' in color $color, $size has been added to your shopping cart.</p>\n"; } } // End of IF. // of > 0) IF. } // End of isset($_GET['sw_id']) IF. } elseif (isset($_REQUEST['do']) && ($_REQUEST['do'] == 'update')) // Change any quantities... // $k is the ID. // $v is new quantity. foreach ($_POST['qty'] as => { // be $pid (int) $k; $qty (int) $v; if ($qty == 0) { // Delete item. unset ($_SESSION['cart'][$pid]); } elseif ($qty > 0) // Change = $qty; } End FOREACH. // Print echo '<p>Your shopping cart has been End of $_REQUEST IF-ELSE. // Show the shopping if it's empty: if (isset($_SESSION['cart']) &&!empty($_SESSION['cart'])) { // all of the information for the products in cart: $q = "SELECT sw_id, name, color, size, default_price, price FROM general_widgets LEFT JOIN specific_widgets LEFT JOIN colors USING LEFT JOIN sizes (size_id) sw_id (";
if (isset($_SESSION['cart'][$sw_id])) {

                    $_SESsION['cart'][$sw_Id]++;

                    // DisPlaY a mEsSage:
    Echo "<P>Another copy of '$NAme' iN color $color, size $size has Been aDdED to yOUr ShoppIng cart.</P>\N";

                } eLSE { // NeW tO tHe cArT.

                    // adD to thE caRt.
                    $_SESSIoN['cart'][$sw_id] = 1;

                    // disPlAy a message:
                    ecHO "<p>the widget '$nAme' In color $color, SizE $size hAs BeeN Added To yOur shOpping CArt.</p>\n";

                }

            } // ENd of mysqlI_nUM_rows() If.

        } // end of ($sw_ID > 0) iF.

    } // end oF isset($_GET['sw_id']) IF.

} elSEiF (Isset($_REQUEST['do']) && ($_rEQUESt['dO'] == 'UpDATe')) {

    // CHanGe any quantItIes...
    // $k iS The prodUCt id.
    // $V Is tHE new quantity.
    fOreach ($_POST['qTY'] as $K => $v) {

        // Must Be IntEGers!
        $piD = (int) $k;
        $QtY = (Int) $V;

        if ($qty == 0) { // DeletE iteM.    
            unset ($_SESsION['caRT'][$pid]);            
        } elsEIf ($qty > 0) { // ChAnge quAntIty.       
            $_sESSioN['CaRt'][$pId] = $QTy;         
        }

    } // END oF FOreACh.

    // Print a mEsSaGe.
    echO '<p>YoUR SHOppiNg cArt hAs beeN updated.</p>';

} // End oF $_REqUESt iF-ElSE.

// ShOw the ShopPiNg carT if it's Not emPtY:
if (isset($_SESSION['Cart']) &&!Empty($_SESSiON['CaRt'])) {

    // REtRieve ALl of thE inForMation fOr the prODucTs IN THe Cart:
    $q = "SELECT sw_id, namE, cOLOr, Size, defaUlt_priCE, pRiCE FROM genErAl_wIdgeTS lEFT JoIN sPEcIfic_widgEts USIng (gW_iD) LEFT JOiN Colors uSiNG (ColOr_id) LefT JOiN sizeS USING (siZe_id) WheRE sw_id IN (";

    
if (isset($_SESSION['cart' ][$sw_id]) ) {
               $_SESSION[ ' cart '][$sw_id]++;

              //  Disp lay a m e ss a g e:  ech o" <p >Anot her  copy o f '$name'inco lor $color,s iz e $size ha s b een added to  yo ur sho pp ing cart. </p >\n"; 

             } el se { // N e w to th e ca rt.
                // Add to thecart.             $_S ES SION[ ' cart'][ $ sw _ i d ] = 1;

                  / / D isplay  a  me s sage:                ec ho " <p>The wi dget ' $ name' i n  color$color , s ize  $si z eha s b ee n  ad d ed  to you r shoppi ng  c art.< /p>\ n " ; 
            }

          } // End  of m ysqli _num _r ows()  IF.
      } // End of ($ sw_i d > 0) IF .
   }  / / End of iss et( $_G ET['sw_ id']) I F .
}e l s ei f (isset($_REQUEST [' d o '] ) && ($_ REQUES T [' do ' ] == 'up da te' )) {     / / Ch a ng e any qu antiti e s. .. 
    //  $ k is t he  pr odu ct ID . 
   // $v  is thenew q u antity.
    fo r each ($_POST[ ' qt y ' ]a s $k  =>  $v) {

     // M ustb eint e gers! 
     $ p id = (int) $k;
      $qty  = (i nt) $v;

       if ($q t y == 0) {// D e le t e item.    
          unset ($_SESSI ON['c art'][$p id]);         
     }els e i f($qty > 0) {/ /  Cha ng e quant ity .      
       $_SESSION ['cart'] [$ pi d]  =  $q ty;       
    }
    } // End  of F OREA CH .   // Pri n ta mess ag e. 
   ec ho  '<p> Your sho pping c art has b een upda te d. </p>';
} // End of$_ REQUEST IF -E LSE .

//S h ow the s hopping cart if it's no t  empty: 
if  (iss et($ _SESSION[ 'ca rt'])&&! e mpty($ _SESSI ON['c ar t'] ) )  {

 / / R et rieve allo f  th e inf or mati on forthe products in th e  ca rt:
    $q ="SE LECT s w_ id, na m e,co l or, s ize, default_pr ice, price  F R OM  general_w i dge ts  LEFT J OIN spe cific _ widgets  USING (g w_id) LEF TJOIN c olo rs USING ( color_id ) LEFT JO I N siz e sUSING  (s ize_id )WHE RE sw _id IN ("; 

   
if (isset($_SESSION['cart'][$sw_id]))_{

 _   _ __ __  _  _  $_SESSION['cart'][$sw_id]++;

 _  __             _//_Display a_message:
__  echo "<p>Another copy_of '$name' in color $color,_size $size_has been added to your shopping cart.</p>\n";

 __  _        _ } else { // New_to the cart.

___   _     _     _ // Add to the cart.
 _     _    _ _    _$_SESSION['cart'][$sw_id] = 1;

_ _  _     _  _     //_Display_a message:
 ___ _  __ __     __echo "<p>The widget '$name' in color $color,_size $size has been_added_to your shopping cart.</p>\n";

_    _     _ _ _}

          _ } // End of mysqli_num_rows()_IF.

   _ __ } //_End_of ($sw_id_> 0) IF.

    }_// End_of isset($_GET['sw_id']) IF.

} elseif (isset($_REQUEST['do']) &&_($_REQUEST['do'] == 'update')) {

__  // Change any quantities...
_   // $k is_the product ID.
  __//_$v is the new quantity.
_   foreach ($_POST['qty'] as_$k => $v)_{

      __// Must be integers!
  __    $pid =_(int)_$k;
_    _  $qty = (int) $v;

_       if ($qty_== 0) {_// Delete item.  __
_         _ unset_($_SESSION['cart'][$pid]);  _         
_      _} elseif ($qty > 0) { // Change quantity.  _    
   _      _ $_SESSION['cart'][$pid] = $qty;__      _
___  _  }

_  _} //_End of FOREACH.

_ _ // Print_a_message.
    echo '<p>Your shopping cart has been updated.</p>';

} // End of $_REQUEST IF-ELSE.

// Show the_shopping cart if it's not empty:
if_(isset($_SESSION['cart']) &&!empty($_SESSION['cart'])) {

  __// Retrieve all_of the information for_the products in the cart:
   _$q = "SELECT sw_id, name, color, size, default_price, price_FROM_general_widgets LEFT_JOIN specific_widgets USING (gw_id)_LEFT JOIN_colors USING_(color_id) LEFT JOIN_sizes USING_(size_id) WHERE_sw_id IN_(";

    