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? 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. 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? 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); 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. 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. Link to comment https://forums.phpfreaks.com/topic/248956-getting-undefined-variable-why/#findComment-1278554 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.