$totalCost=0;
while($row = $result->fetch_assoc())
{
$totalCost+=$row["price"];
------------------------------
--->why the $totalCost always is 0?

does row["price"] have a value in it? Php let you assign empty array items. Try add echo $row to the loop and make sure that it is not empty.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.