Jump to content

Value isn't processing properly in If Statements??


suess0r

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.