Freedom-n-Democrazy Posted October 12, 2011 Share Posted October 12, 2011 I'm getting: PHP Notice: Undefined variable: carttotal ... for this: $idtotal = $sizestotal + $sizemtotal + $sizeltotal + $sizexltotal; $carttotal += $idtotal; Why? Quote Link to comment https://forums.phpfreaks.com/topic/248956-getting-undefined-variable-why/ Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 12, 2011 Author Share Posted October 12, 2011 $carttotal = +$idtotal; EDIT: While this stopped the PHP notice, it made my calculation thing stop working. Quote Link to comment https://forums.phpfreaks.com/topic/248956-getting-undefined-variable-why/#findComment-1278520 Share on other sites More sharing options...
trq Posted October 12, 2011 Share Posted October 12, 2011 Have you defined $carttotal anywhere before trying to add to it? Quote Link to comment https://forums.phpfreaks.com/topic/248956-getting-undefined-variable-why/#findComment-1278525 Share on other sites More sharing options...
MasterACE14 Posted October 12, 2011 Share Posted October 12, 2011 Have you defined $carttotal anywhere before trying to add to it? something like this would be fine: $carttotal = 0; // set default $idtotal = $sizestotal + $sizemtotal + $sizeltotal + $sizexltotal; $carttotal += $idtotal; or even... $carttotal = 0; // set default $carttotal += ($sizestotal + $sizemtotal + $sizeltotal + $sizexltotal); Quote Link to comment https://forums.phpfreaks.com/topic/248956-getting-undefined-variable-why/#findComment-1278526 Share on other sites More sharing options...
AyKay47 Posted October 12, 2011 Share Posted October 12, 2011 rule of thumb when trying to increment/decrement a variable, the variable must always be set to a value before it can be incremented or decremented. Quote Link to comment https://forums.phpfreaks.com/topic/248956-getting-undefined-variable-why/#findComment-1278540 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 12, 2011 Author Share Posted October 12, 2011 Hey guys, Nah I hadn't but someone from codingforums.com helped me out so I've got it all sorted. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/248956-getting-undefined-variable-why/#findComment-1278554 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.