Click here to Skip to main content
15,881,828 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
AnswerRe: PHP 8.1 Count issue Pin
Richard MacCutchan30-Mar-23 0:45
mveRichard MacCutchan30-Mar-23 0:45 
AnswerRe: PHP 8.1 Count issue Pin
Richard Deeming30-Mar-23 0:45
mveRichard Deeming30-Mar-23 0:45 
GeneralRe: PHP 8.1 Count issue Pin
Aruna KN30-Mar-23 1:38
Aruna KN30-Mar-23 1:38 
GeneralRe: PHP 8.1 Count issue Pin
Richard Deeming30-Mar-23 2:53
mveRichard Deeming30-Mar-23 2:53 
GeneralRe: PHP 8.1 Count issue Pin
Aruna KN30-Mar-23 3:21
Aruna KN30-Mar-23 3:21 
QuestionIf command triggering at wrong time with PHP 8.1 Pin
Aruna KN29-Mar-23 18:56
Aruna KN29-Mar-23 18:56 
AnswerRe: If command triggering at wrong time with PHP 8.1 Pin
Richard Deeming29-Mar-23 21:22
mveRichard Deeming29-Mar-23 21:22 
GeneralRe: If command triggering at wrong time with PHP 8.1 Pin
Aruna KN29-Mar-23 21:27
Aruna KN29-Mar-23 21:27 
GeneralRe: If command triggering at wrong time with PHP 8.1 Pin
Aruna KN29-Mar-23 22:15
Aruna KN29-Mar-23 22:15 
QuestionBlank space or NULL with PHP 8.1 Pin
Aruna KN14-Mar-23 22:57
Aruna KN14-Mar-23 22:57 
AnswerRe: Blank space or NULL with PHP 8.1 Pin
Richard MacCutchan15-Mar-23 7:10
mveRichard MacCutchan15-Mar-23 7:10 
QuestionPHP Fatal error: Uncaught TypeError: count() Pin
Aruna KN10-Mar-23 20:17
Aruna KN10-Mar-23 20:17 
AnswerRe: PHP Fatal error: Uncaught TypeError: count() Pin
Graham Breach11-Mar-23 1:45
Graham Breach11-Mar-23 1:45 
GeneralRe: PHP Fatal error: Uncaught TypeError: count() Pin
Aruna KN11-Mar-23 16:32
Aruna KN11-Mar-23 16:32 
Questionhtaccess %3F redirect issue Pin
Aruna KN10-Mar-23 19:40
Aruna KN10-Mar-23 19:40 
QuestionHow to develop a game using implement the api Pin
piumini sakunthala2-Feb-23 21:06
piumini sakunthala2-Feb-23 21:06 
QuestionRe: How to develop a game using implement the api Pin
Richard MacCutchan2-Feb-23 21:41
mveRichard MacCutchan2-Feb-23 21:41 
QuestionWordpress shortcode prints wrong value from custom post type Pin
moinmobility9-Oct-22 7:36
moinmobility9-Oct-22 7:36 
Questionimplement ElFinder in PHP language Pin
Alexis Sanchez Vanegas19-May-22 4:28
Alexis Sanchez Vanegas19-May-22 4:28 
QuestionAapanel upload project laravel Pin
marziyeh barooei9-May-22 1:05
marziyeh barooei9-May-22 1:05 
Questionhow do I get total quantity from this code Pin
wixily jnr28-Apr-22 13:29
wixily jnr28-Apr-22 13:29 
PHP
<?php 
session_start();

ini_set('display_errors', 1);
error_reporting(E_ALL);

define("PRODUCTIMAGE",0);
define("PRODUCTCODE", 1);
define("PRODUCTNAME", 2);
define("QUANTITY", 3);
define("PRICE", 4);

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
   if (isset($_POST['productcode']))
   {
      AddToCart();
   }
   else
   {
      $action = isset($_POST['action']) ? $_POST['action'] : '';
      $value = strtoupper(substr($action, 0, 5));
      switch ($value)
      {
      // continue shopping
      case "CONTI":
         header("Location: "."products.html");
         break;

      // recalculate
      case "RECAL": 
         RecalculateCart();
         break;

      // proceed to checkout
      case "CHECK":
         header("Location: "."customer.php");
         break;
      } 
   }
} 


function AddToCart()
{
   $cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : '';
   $itemcount = isset($_SESSION['itemcount']) ? $_SESSION['itemcount'] : 0;

$productname = $_POST['productname'];
$extra_price = 0;
$productname = stripslashes($productname);

// Let's see if this product already exists
   for ($i=0; $i < $itemcount; $i++)
   {
     if ($cart[PRODUCTNAME][$i] == $productname) {
         $cart[QUANTITY][$i] = $cart[QUANTITY][$i] + intval($_POST['quantity']);
         $_SESSION['cart'] = $cart;
         $_SESSION['itemcount'] = $itemcount;
         header("Location: "."cart.php");
         exit;
   }
   }

   $cart[PRODUCTIMAGE][$itemcount] = $_POST['productimage'];
   $cart[PRODUCTCODE][$itemcount] = $_POST['productcode'];
   $cart[PRODUCTNAME][$itemcount] = $_POST['productname'];
   $cart[QUANTITY][$itemcount] = intval($_POST['quantity']);
   $cart[PRICE][$itemcount] = $_POST['price'];
   $itemcount = $itemcount + 1;

   $_SESSION['cart'] = $cart;
   $_SESSION['itemcount'] = $itemcount;
} 


function RecalculateCart()
{
   $cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : '';
   $itemcount = isset($_SESSION['itemcount']) ? $_SESSION['itemcount'] : 0;

   for ($i=0; $i<$itemcount; $i++)
   {
      $quantity = $_POST['quantity'.($i)];
      if (empty($quantity))
      {
         $quantity = 0;
      }
      else
      if (($quantity < 0) || (!is_numeric($quantity)))
      {
         $quantity = 0;
      } 
      $cart[QUANTITY][$i] = intval($quantity);
   }

   for ($j=0; $j<$itemcount; $j++)
   {
      $quantity = $cart[QUANTITY][$j];

      // remove item from the cart
      if ($quantity == 0)
      {
         $itemcount--;
        
         $curitem = $j;

         while(($curitem+1) < count($cart[0]))         
         {
            for ($k=0; $k<4; $k++)
            {
               $cart[$k][$curitem] = $cart[$k][$curitem+1];
               $cart[$k][$curitem+1] = '';
            }
            $curitem++;
         } 
      } 
   }
   $_SESSION['itemcount'] = $itemcount;
   $_SESSION['cart'] = $cart;
} 

?>


modified 29-Apr-22 3:30am.

AnswerRe: how do I get total quantity from this code Pin
Richard MacCutchan28-Apr-22 21:31
mveRichard MacCutchan28-Apr-22 21:31 
QuestionROLES ET PRIVILEGES UTILISATEURS D'UN SITE Pin
ameb290825-Apr-22 4:06
ameb290825-Apr-22 4:06 
QuestionHow can I do a google search and get results in backend using JS or PHP? Pin
Social Bookmarking Site14-Apr-22 15:27
Social Bookmarking Site14-Apr-22 15:27 
Questionproblem in pagination click Pin
irfankundi7861-Apr-22 23:39
irfankundi7861-Apr-22 23:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.