Getting warning A non-numeric value encountered when data is "numeric"!

Hello sir,
I am new learner of PHP-PDO-MYSql, getting a Warning: “A non-numeric value encountered in …test.php on line 35

When database has numeric value and field structure is set to INT. When I echo, I get the numeric value! I am not able to detect the error I am doing! Please help. Here is the code containing line 35 [ $totalRevenue += $orderResult[‘paid’]; ]

$orderSql = "SELECT * FROM orders WHERE order_status = 1";
$orderQuery = $connect->query($orderSql);
$countOrder = $orderQuery->num_rows;

$totalRevenue = "";
$orderResult  = "";

while ($orderResult = $orderQuery->fetch_assoc()) {
	$totalRevenue += $orderResult['paid'];   // this is the warning line
	
        //$totalRevenue = $totalRevenue + $orderResult['paid'];
	//echo $totalRevenue;
	
}

Thank you for your time spending for helping me.

Hello and welcome to the forum :slight_smile:

try setting the variables to null or zero instead of assigning an empty string

then post in the beginners section for clarification concerning future posts.

2 Likes

echo is incapable for detecting any variable type, use var_dump

1 Like

Thank you @ johnphpnewb, I will remember you suggestion. Setting values zero is worked. I forgot " " values are string. Thanks again.

Thank you @chorn, I will use var_dump.

Sponsor our Newsletter | Privacy Policy | Terms of Service