NewDeveloper NewDeveloper -4 years ago 207
PHP Question

A non-numeric value encountered in php

I am trying to get the quantity in text field and multiply it with the total price,but i always got the following error,can anyone help me in that?


Warning: A non-numeric value encountered


<table class="table">
<tr align="center">
<th>Remove</th>
<th>Product(S)</th>
<th>Quantity</th>
<th>Total Price</th>
</tr>
<?php
$total = 0;
global $con;
$ip = getIp();
$sel_price = "SELECT * FROM Cart WHERE IP_Address='$ip'";
$pricerows = $con->query($sel_price)->fetchall(PDO::FETCH_ASSOC);
foreach ($con->query($sel_price) as $row_price) {
$pro_id = $row_price['Product_ID'];
$pro_price = "SELECT * FROM Products WHERE Product_ID='$pro_id'";
foreach ($con->query($pro_price) as $row_proprice) {
$product_price = array($row_proprice['Price']);
$product_title = $row_proprice['Product_Name'];
$product_imaage = $row_proprice['Photo'];
$single_price = $row_proprice['Price'];
$values = array_sum($product_price);
$total += $values;
?>
<tr align="center">
<td><input type="checkbox" name="remove[]" value="<?php echo $pro_id; ?>"></td>
<td><?php echo $product_title; ?><br><img src="images/<?php echo $product_imaage; ?>" width="60" height="60"/></td>
<td><input type="text" size="4" id="qty" name="qty" value="<?php echo $_SESSION['qty'];?>"/></td>
<?php

if (isset($_POST['update_cart'])) {

$qty = $_POST['qty'];
$update_qty = "UPDATE cart set Quantity='$qty'";
$updaterows = $con->prepare($update_qty);
$updaterows->execute();

$_SESSION['qty'] = $qty;

$total = $total*$qty; //ERROR APPEARS HERE

}
?>
<td><?php echo $single_price . " L.E";?></td>
</tr>
</table>

Answer Source

You need to convert the value to integer, you can use

int(your value) 

$total = $total* int($qty); 

I hope this will solve the problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download