简体   繁体   English

警告:PHP MySQL 遇到非数字值

[英]Warning: A non-numeric value encountered PHP MySQL

I get a warning:我收到警告:

Warning: A non-numeric value encountered in C:\\xampp\\htdocs\\epard\\cart.php on line 110警告:在第 110 行的 C:\\xampp\\htdocs\\epard\\cart.php 中遇到非数字值

$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.重要的是,cartTotal 完美运行。 It counts the price of every item, but it still show that warning.它计算每件商品的价格,但它仍然显示该警告。 Is there any way to remove that warning?有什么办法可以消除那个警告吗?

So line 110 is $cartTotal = $pricetotal + $cartTotal;所以第 110 行是$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;所以像这样初始化你的变量: $cartTotal = 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;所以像这样初始化你的变量: @$abc = $DEF;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM