suess0r Posted August 24, 2007 Share Posted August 24, 2007 OK - I know this is probably sloppy coding.. but here's the gist of what i'm trying to do. I want to print $total according to which 2 values were chosen from $size and $quantity. But the $total always stays the value of each If validation section.. So if the $size = postcard4-6 then the $total is always 324.95 instead of 39.95 <?php $size = $_POST['postcard-size']; $quantity = $_POST['postcard-quantity']; $error = 1; echo $size; echo $quantity; if ($size == "") $total = 0.00; if (!isset($quantity)) $total = 0.00; //Note: Need validation for if isset($size) && !isset($quantity) if (isset($size, $quantity)) { //Validation for Postcard 4x6 if ($size == "postcard4-6" && $quantity = 100) { $total = 39.95; } if ($size == "postcard4-6" && $quantity = 250){ $total = 79.95; } if ($size == "postcard4-6" && $quantity = 500){ $total = 89.95; } if ($size == "postcard4-6" && $quantity = 1000){ $total = 114.95; } if ($size == "postcard4-6" && $quantity = 2500){ $total = 229.95; } if ($size == "postcard4-6" && $quantity = 5000){ $total = 324.95; } //Validation for Postcard 8.5x5.5 if ($size == "postcard85-55" && $quantity = 100) { $total = 69.95; } if ($size == "postcard85-55" && $quantity = 250){ $total = 119.95; } if ($size == "postcard85-55" && $quantity = 500){ $total = 149.95; } if ($size == "postcard85-55" && $quantity = 1000){ $total = 229.95; } if ($size == "postcard85-55" && $quantity = 2500){ $total = 399.95; } if ($size == "postcard85-55" && $quantity = 5000){ $total = 589.95; } //Validation for Postcard 8.5x5.5 if ($size == "postcard6-11" && $quantity = 100) { $total = 0.00; //$error = 2; } if ($size == "postcard6-11" && $quantity = 250){ $total = 0.00; //$error = 2; } if ($size == "postcard6-11" && $quantity = 500){ $total = 0.00; //$error = 2; } if ($size == "postcard6-11" && $quantity = 1000){ $total = 349.95; } if ($size == "postcard6-11" && $quantity = 2500){ $total = 499.95; } if ($size == "postcard6-11" && $quantity = 5000){ $total = 799.95; } } $total = number_format($total, 2, '.', ''); echo '$'.$total; //if ($error = 2) //echo "$0.00 Sorry, you need to select 1,000+ to get postcards in 6x11"; // echo ' <input type="hidden" name="amount" value="'.$total.'">'; ?> I've tried swapping the '=' with '==' in the if statement.. ex: if ($size == "postcard6-11" && $quantity == 1000){ $total = 349.95; that didn't help. I echo'd my $size and $quantity and i'm getting all the right values - like in the above example i get $size = postcard6-11 and $quantity = 1000.. i'm sure i'm just doing something stupid (my PHP is a bit rusty).. Link to comment https://forums.phpfreaks.com/topic/66511-value-isnt-processing-properly-in-if-statements/ Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 Change all the extra if's that set the $total to else if's: if ($size == "postcard4-6" && $quantity = 100) { $total = 39.95; } else if ($size == "postcard4-6" && $quantity = 250){ $total = 79.95; } else if ($size == "postcard4-6" && $quantity = 500){ $total = 89.95; } else if ($size == "postcard4-6" && $quantity = 1000){ $total = 114.95; } etc... That will make only one possibility for $total. Link to comment https://forums.phpfreaks.com/topic/66511-value-isnt-processing-properly-in-if-statements/#findComment-333075 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.