Reputation: 987
I'm currently trying to create a final total method using PHP. So far I keep getting this error for the following code:
Notice: Undefined variable: finalTotal
The method does work and the final amount is calculated however I am not sure how to define the $finalTotal variable so no errors turn up. Any tips would be appreciated.
Here is the code
$tot1=$row['productvalue']*$value;
$finalTotal +=$tot1;
}
echo $finalTotal;
Any tips are appreciated
Upvotes: 0
Views: 76
Reputation: 2948
It's always good practice to initialize your variable, at least IMO. In this case, to 0.
Upvotes: 0
Reputation: 218872
What if you add like this
$finalTotal=0;
//your loop
$tot1=$row['productvalue']*$value;
// rest of code
Upvotes: 0
Reputation: 9402
Make sure you initialize finalTotal
before.
$fintalTotal = 0;
Than, perform your actions.
Upvotes: 2