-2

I get a warning:

Warning: A non-numeric value encountered in C:\xampp\htdocs\epard\cart.php on line 110

$cartOutput = "";
$cartTotal = "";
$pp_checkout_btn = '';
$product_id_array = '';
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
  $cartOutput = "<h2 align='center'>Jūsų krepšelis tuščias</h2>";
} else {

  // Start the For Each loop

  $i = 0; 
  foreach ($_SESSION["cart_array"] as $each_item) { 
    $item_id = $each_item['item_id'];
    $sql = mysqli_query($con, "SELECT * FROM prekes WHERE id='$item_id' LIMIT 1");
    while ($row = mysqli_fetch_array($sql)) {
      $pavadinimas = $row["pavadinimas"];
      $kaina = $row["kaina"];
      $gamintojas = $row["gamintojas"];
    }
    $pricetotal = $kaina * $each_item['quantity'];
    $cartTotal = $pricetotal + $cartTotal;
    setlocale(LC_MONETARY, "en_EU");

    // Create the product array variable

    $product_id_array .= "$item_id-".$each_item['quantity'].","; 

    // Dynamic table row assembly

    $cartOutput .= "<tr>";
    $cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $pavadinimas . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $pavadinimas. '" width="40" height="52" border="1" /></td>';
    $cartOutput .= '<td>' . $gamintojas . '</td>';
    $cartOutput .= '<td>€' . $kaina . '</td>';
    $cartOutput .= '<td><form action="cart.php" method="post">
    <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" />
    <input class="btn btn-primary btn-sm" name="adjustBtn' . $item_id . '" type="submit" value="change" />
    <input name="item_to_adjust" type="hidden" value="' . $item_id . '" />
    </form></td>';
    //$cartOutput .= '<td>' . $each_item['quantity'] . '</td>';
    $cartOutput .= '<td>€' . $pricetotal . '</td>';
    $cartOutput .= '<td><form action="cart.php" method="post"><input class="btn btn-danger btn-sm" name="deleteBtn' . $item_id . '" type="submit" value="X" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>';
    $cartOutput .= '</tr>';
    $i++; 
} 
setlocale(LC_MONETARY, "en_US");
$cartTotal = "<div style='font-size:18px; margin-top:12px;' align='right'>Krepšelio suma : ".$cartTotal." EUR</div>";
}

And important part is that cartTotal works perfectly. It counts the price of every item, but it still show that warning. Is there any way to remove that warning?

Arminas Šaltenis
  • 166
  • 1
  • 2
  • 10

2 Answers2

7

So line 110 is $cartTotal = $pricetotal + $cartTotal;

Have a look at how you set these values.
Second line of your code. $cartTotal = "";
"" is not a number!

So initialize your variable like this: $cartTotal = 0;

Nic3500
  • 8,144
  • 10
  • 29
  • 40
0

Have a look at how you set these values. Second line of your code. $abc = $DEF;

So initialize your variable like this: @$abc = $DEF;

DAG
  • 6,710
  • 4
  • 39
  • 63