Link to home
Start Free TrialLog in
Avatar of Johnny
JohnnyFlag for United States of America

asked on

need to cycle thru if item is present and add descriptions with prices

how do i make this php code work please.
im trying to check if item 1 thru 4 has a value if it does it builds a string to display the description and value of each item
im having trouble with adding another value the current routine does not cycle till done only reads one item

i have a while loop going but i am unsure of how to add that to the loop

thank you in advance for any help and code you may provide
while($i <= 4)
{
  if($HTTP_POST_VARS["item$i"] != NULL)
  {
    if($count == 0)
      $items .= $HTTP_POST_VARS["item$i"];
    else
      $items .= ",".$HTTP_POST_VARS["item$i"];
 
      $count++;
  }
  $i++;
  next;
}
 
  print "Thank you, ".$HTTP_POST_VARS['FirstName']." For your order.<BR> Item(s) purchased are: ".$items . "<BR>";
 
____________________________________________
 
 
    // Add items to the cart
 
 
$subTaxTotal=0;
$x_Amount=0;
$x_Description="";
 
if (isset($_POST['item1'])) {
$subTotal =$Loft_Price;
$tax = round($subTotal / 100 * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;
 
    $x_Description = "Loft Bed Rental ( Wittenberg ONLY) - Space-saving comfortable loft bed";
    $x_Amount=$subTaxTotal;
 
}
 
if (isset($_POST['item2'])) {
$subTotal =$MicroFride_Price;
$tax = round($subTotal / 100 * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;
 
    $x_Description = "MicroFridge Rental - Compact 2 door fridge and freezer with attached microwave";
    $x_Amount=$subTaxTotal;
	}
 
if (isset($_POST['item3'])) {
$subTotal =$Safe_Rental;
$tax = round($subTotal / 100 * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;
    $x_Description = "Electronic Safe Rental - 1.19 cu. ft. Electronic Safe";
    $x_Amount=$subTaxTotal;
}
 
if (isset($_POST['item4'])) {
$subTotal =$Safe_Purchase_Price;
$tax = round($subTotal / 100 * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;
 
    $x_Description = "Electronic Safe Purchase - 1.19 cu. ft. Electronic Safe";
    $x_Amount=$subTaxTotal;
 
}
 
else {
    $x_Description = "error: no items found - didnt capture posted item";
    $x_Amount=$subTaxTotal;
 
}

Open in new window

Avatar of musicmasteria
musicmasteria

I'm confused what you are trying to do.

First thing I notice is this:
$items .= $HTTP_POST_VARS["item$i"];

I believe that $i should have { } around it, ex:
$items .= $HTTP_POST_VARS["item{$i}"];


Next thing, (with previous thing changed)
if($count == 0)
      $items .= $HTTP_POST_VARS["item{$i}"];
       // ----- Why no $count++; here?
    else
      $items .= ",".$HTTP_POST_VARS["item{$i}"];
 
      $count++;
  }

Next thing after that,
if (isset($_POST['item1'])) {
$subTotal =$Loft_Price;
$tax = round($subTotal / 100 * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;
 
    $x_Description = "Loft Bed Rental ( Wittenberg ONLY) - Space-saving comfortable loft bed";
    $x_Amount=$subTaxTotal;
 
}

That could be a while loop with a count variable replacing 1 in:
if (isset($_POST['item1'])) {

You would have to have a total item count for that to work but it would make your script allow for more variable numbers of items

I fixed a couple other things in the code as well and attached it below (but I didn't test it)
Try it out and see if it works
$i = 1; //before it was NULL I believe
while($i <= 4){
  if($HTTP_POST_VARS["item$i"] != NULL){
    if($count == 0){ // YOU FORGOT THESE
      $items .= $HTTP_POST_VARS["item{$i}"];
      $count++;
    }else{ // These Too
      $items .= ",".$HTTP_POST_VARS["item{$i}"];
      $count++;
    } // And this :P lol
  }
  $i++;
  //next; <-- what was this?
}
 
  print "Thank you, ".$HTTP_POST_VARS['FirstName']." For your order.<BR> Item(s) purchased are: ".$items . "<BR>";
 
//____________________________________________
 
 
    // Add items to the cart
 
 
$subTaxTotal=0;
$x_Amount=0;
$x_Description="";
 
if (isset($_POST['item1'])) {
$subTotal =$Loft_Price;
$tax = round($subTotal / 100 * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;
 
    $x_Description = "Loft Bed Rental ( Wittenberg ONLY) - Space-saving comfortable loft bed";
    $x_Amount=$subTaxTotal;
 
}
 
if (isset($_POST['item2'])) {
$subTotal =$MicroFride_Price;
$tax = round($subTotal / 100 * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;
 
    $x_Description = "MicroFridge Rental - Compact 2 door fridge and freezer with attached microwave";
    $x_Amount=$subTaxTotal;
        }
 
if (isset($_POST['item3'])) {
$subTotal =$Safe_Rental;
$tax = round($subTotal / 100 * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;
    $x_Description = "Electronic Safe Rental - 1.19 cu. ft. Electronic Safe";
    $x_Amount=$subTaxTotal;
}
 
if (isset($_POST['item4'])) {
$subTotal =$Safe_Purchase_Price;
$tax = round($subTotal / 100 * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;
 
    $x_Description = "Electronic Safe Purchase - 1.19 cu. ft. Electronic Safe";
    $x_Amount=$subTaxTotal;
 
}
 
else {
    $x_Description = "error: no items found - didnt capture posted item";
    $x_Amount=$subTaxTotal;
 
}

Open in new window

Avatar of Johnny

ASKER

the problem is if more then one item is used it does capture that info in my count loop but does not add the description to the description var and total the sum of the items bought. and thats what I'm looking for.

thank you for cleaning up my code ill try and work on it today at the office. and see if it improves the code. but i still need it to join the prices and the item descriptions too.

thanks again
ps: see the complete file attached that I'm using to process the cart info
proccess-auth-dot-net.txt
Avatar of Johnny

ASKER

i need the description field to reflect if a safe and microfridge has been rented together and the sum to be added for the total price too. in its current state it only reads one of them i was unsure of how to add it to the while loop
Avatar of Johnny

ASKER

ive been woirking on the code and i broke it

---------- this works fine-----------
<?php
$tax_rate="7.0";
$Safe_Purchase_Price="199.00";
$Calc_Tax_Total=(($Safe_Purchase_Price/100) * $tax_rate);
$tax = round($Calc_Tax_Total,2);
$subTaxTotal = ($Safe_Purchase_Price + $tax);

    $x_description = "yes-Electronic Safe Purchase - 1.19 cu. ft. Electronic Safe";
    $x_amount=$subTaxTotal;
?>
Playing with Safe_Purchase_Price info <br/>
Description: <?=$x_description?>  <BR />
Item Amount : <?=$Safe_Purchase_Price?>  <BR />
Tax Rate:<?=$tax_rate?>  <BR />
Tax Calc:<?=$Calc_Tax_Total?>  <BR />
Tax Amount : <?=$tax?>  <BR />
Tax included - Total Amount : <?=$subTaxTotal?>  <BR />
Total Amount : <?=$x_amount?>  <BR />

------------------------------
the current file does not work math wise.. and the descriptions are not working as well only the safe purchase.
sorry to be such a bother and i don't know this part of php very well to fix this
thanks for any help you may provide

correct function should be listed descriptions and total amount added up for all items picked

proccess-auth-dot-net.txt
Ok your last post with the broken code is obvious.

Description: <?=$x_description?>  <BR />
Item Amount : <?=$Safe_Purchase_Price?>  <BR />
Tax Rate:<?=$tax_rate?>  <BR />
Tax Calc:<?=$Calc_Tax_Total?>  <BR />
Tax Amount : <?=$tax?>  <BR />
Tax included - Total Amount : <?=$subTaxTotal?>  <BR />
Total Amount : <?=$x_amount?>  <BR />

"<?=$x_description?>" is not the right format. It should be "<?php echo $x_description; ?>"
I assumed you want to have it type out the vars value. That's called an 'echo'
Also, don't forget the trailing ';' on every line of php

So that whole code should look like this:
<?php
$tax_rate="7.0";
$Safe_Purchase_Price="199.00";
$Calc_Tax_Total=(($Safe_Purchase_Price/100) * $tax_rate);
$tax = round($Calc_Tax_Total,2);
$subTaxTotal = ($Safe_Purchase_Price + $tax);
 
   $x_description = "yes-Electronic Safe Purchase - 1.19 cu. ft. Electronic Safe";
   $x_amount=$subTaxTotal;
?>
Playing with Safe_Purchase_Price info<br/>
Description: <?php echo $x_description; ?><br/>
Item Amount : <?php echo $Safe_Purchase_Price; ?><br/>
Tax Rate:<?php echo $tax_rate; ?><br/>
Tax Calc:<?php echo $Calc_Tax_Total; ?><br/>
Tax Amount : <?php echo $tax; ?><br/>
Tax included - Total Amount : <?php echo $subTaxTotal; ?><br/>
Total Amount : <?php echo $x_amount; ?><br/>

Open in new window

Avatar of Johnny

ASKER

this is the current file im working on
http://www.openspaceconcepts.com/openspace/proccess_auth-dot-net.txt

this is the snip i made to check the math it calculates correctly
http://www.openspaceconcepts.com/openspace/tax.php

this is the form im trying to get to work with mutable items selected then passed to the process php we are working on.
as you can see its a almost duplicate of the tax snip i did as i cut and pasted the info from the process php file and it is broken in the process php file but not in the snip

http://www.openspaceconcepts.com/openspace/open_order3.php


so i have 2 problems now. fixing the math as it seams to of been broken all along and the listing out the item description(think i got that part to work now) but does not seam to be right in all combination's.

i have to have either syntax errors or something of the like.

thanks for pointing out my errors. most kind of you.
but we still have not hit on the problem of the math not working correctly and the discriptions not displaying as picked, im supper open to a rewrite of the routine.. this is a put together of how i thought it would work and i seam to be guessing now and not making it work. i do need this as soona s posible my boss keeps poping in his head. are you dont yet.. and im getting lost on why its broken nbow.



"the problem is if more then one item is used it does capture that info in my count loop but does not add the description to the description var and total the sum of the items bought. and that's what I'm looking for."

It could have been that you did not have your if statement in the while loop formatted correctly. It was missing all the curly brackets { } { }

I looks in the process-auth-don-net.txt file you attached earlier. I notice that quite a lot of lines are commented out. That could be breaking some of the functionality of the script but it is unclear to me if that is the case or not without deeper insight into how the script was made and who made it.

I believe I fixed the if statement in the file so I'll attach that updated file below. Test it out and see what it does. Is there a way that I might see the output of the test as well?


proccess-auth-dot-net.txt
Oh let me correct myself,
<?=$x_description?>
and
<?php echo $x_description; ?>

The first is a short code version of the second. Now the first code can work but only if the server has short codes enabled. If you are having problems with them as short codes, it's probably off on your sever, if not, you could probably disregard what I said before about them.

As for the math part, show me what you are having a problem with. I can't seem to find it in the process-auth-dot.net.txt script.

Then a recommendation for you,
go through and search for all your IF statements

I notice that you are not using curly brackets on a couple of them.

The format goes like this:
if ( *something that returns True/False* ) {
// something to do if true
} else {
// something to do if false
}

Also, you have quite a lot of commented lines. You should go through those and see which ones you actually need and clean up your code if you can. A cleaner code allows you to find problems much easier.

:)
Avatar of Johnny

ASKER

this is the section I'm working on now.. see attached code - if theirs a better way to do it I'm all open to it.

it broken on the math and the discriptions dont all the time populate corectly from the form in multible items picked ie
------------------------------ snip ---------------
you have you have 2 purchases. They are: Loft,Safe Rental
-------------------------------------------------
that line works fine but the item description does not but if picked
----------------- snip ----------------
you have you have 2 purchases. They are: MicroFridge,Safe Purchase
Description:
  MicroFridge Rental - Compact 2 door fridge and freezer with attached microwave
 Electronic Safe Purchase - 1.19 cu. ft. Electronic Safe
----------------------------
that works just fine for the descriptions.

the math does not work either, but does work fine if taken and placed in another php file as i have shown before.
im going to work on cleaning the code up some and ill post the finshed php file.
and see if i cant comment some of it too. and the changes you asked for
thanks for the help so far


$subTaxTotal="";
$x_amount="";
$x_description="<br> ";
 
 
if (strstr($items, "Loft")) {
$subTotal = $Loft_Price;
$tax = round(($subTotal / 100) * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;
 
    $x_description .= " Loft Bed Rental ( Wittenberg ONLY) - Space-saving comfortable loft bed <br>";
    $x_amount.=$subTaxTotal;
}
 
if (strstr($items, "MicroFridge")) {
$subTotal = $MicroFridge_Price;
$tax = round(($subTotal / 100) * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;
 
    $x_description .= " MicroFridge Rental - Compact 2 door fridge and freezer with attached microwave <br>";
    $x_amount.=$subTaxTotal;
}
 
if (strstr($items, "Safe Rental")) {
$subTotal = $Safe_Rental;
$tax = round(($subTotal / 100) * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;
    $x_description .= " Electronic Safe Rental - 1.19 cu. ft. Electronic Safe <br>";
    $x_amount.=$subTaxTotal;
}
 
if (strstr($items, "Safe Purchase")) {
$subTotal = $Safe_Purchase_Price;
$tax = round(($subTotal / 100) * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;
    $x_description .= " Electronic Safe Purchase - 1.19 cu. ft. Electronic Safe <br>";
    $x_amount.=$subTaxTotal;
}
else {
    $x_description = "error: no items found - didnt capture posted item";
    $x_amount=$subTaxTotal;
}

Open in new window

Avatar of Johnny

ASKER

i cleaned up the code, still the same problems.

isn't there a way to turn on error checking to see if maybe it will trigger an error?
like a debug mode i forgot how to do that right now

ill try to look that up



proccess-auth-dot-net.txt
Avatar of Johnny

ASKER

i made a few more changes mainly added the error php code to report all and cleaned up the vars i could rest are ones i cant clean up like the items 1-4 vars and one for the host capture(didn't want to mess with that at all as it works



proccess-auth-dot-net.txt
I have not tested anything, but instead of $HTTP_POST_VARS use $_POST and better check if not empty like the following:

not:
if($HTTP_POST_VARS["item$i"] != NULL){

better:
if(!empty($_POST["item$i"])){

K I found something on the $x_description and $x_amount problems:

if (strstr($items, "Loft")) {
$subTotal = $Loft_Price;
$tax = round(($subTotal / 100) * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;

    $x_description .= " Loft Bed Rental ( Wittenberg ONLY) - Space-saving comfortable loft bed <br>";
    $x_amount.=$subTaxTotal;
}

if (strstr($items, "MicroFridge")) {
$subTotal = $MicroFridge_Price;
$tax = round(($subTotal / 100) * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;

    $x_description .= " MicroFridge Rental - Compact 2 door fridge and freezer with attached microwave <br>";
    $x_amount.=$subTaxTotal;
}

if (strstr($items, "Safe Rental")) {
$subTotal = $Safe_Rental;
$tax = round(($subTotal / 100) * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;
    $x_description .= " Electronic Safe Rental - 1.19 cu. ft. Electronic Safe <br>";
    $x_amount.=$subTaxTotal;
}

if (strstr($items, "Safe Purchase")) {
$subTotal = $Safe_Purchase_Price;
$tax = round(($subTotal / 100) * $tax_rate,2);
$subTaxTotal = $subTotal + $tax;
    $x_description .= " Electronic Safe Purchase - 1.19 cu. ft. Electronic Safe <br>";
    $x_amount.=$subTaxTotal;
}
else {
    $x_description = "error: no items found - didnt capture posted item";
    $x_amount=$subTaxTotal;
}


This code will overwrite everthing with the error message "error:no items found..." if Safe Purchase is not in the list of items.

Try something like this: (!empty($items) might not be the way to go but it could work as long as you didn't put anything in $items when no items are selected)

As usual, try it out and see what happens
if (!empty($items)){
 
	if (strstr($items, "Loft")) {
	$subTotal = $Loft_Price;
	$tax = round(($subTotal / 100) * $tax_rate,2);
	$subTaxTotal = $subTotal + $tax;
	
	    $x_description .= " Loft Bed Rental ( Wittenberg ONLY) - Space-saving comfortable loft bed <br>";
	    $x_amount.=$subTaxTotal;
	}
 
	if (strstr($items, "MicroFridge")) {
	$subTotal = $MicroFridge_Price;
	$tax = round(($subTotal / 100) * $tax_rate,2);
	$subTaxTotal = $subTotal + $tax;
 
	    $x_description .= " MicroFridge Rental - Compact 2 door fridge and freezer with attached microwave <br>";
	    $x_amount.=$subTaxTotal;
	}
	
	if (strstr($items, "Safe Rental")) {
	$subTotal = $Safe_Rental;
	$tax = round(($subTotal / 100) * $tax_rate,2);
	$subTaxTotal = $subTotal + $tax;
	    $x_description .= " Electronic Safe Rental - 1.19 cu. ft. Electronic Safe <br>";
	    $x_amount.=$subTaxTotal;
	}
 
	if (strstr($items, "Safe Purchase")) {
	$subTotal = $Safe_Purchase_Price;
	$tax = round(($subTotal / 100) * $tax_rate,2);
	$subTaxTotal = $subTotal + $tax;
	    $x_description .= " Electronic Safe Purchase - 1.19 cu. ft. Electronic Safe <br>";
	    $x_amount.=$subTaxTotal;
	}
 
} else {
	$x_description = "error: no items found - didnt capture posted item";
	$x_amount=$subTaxTotal;
}

Open in new window

Avatar of Johnny

ASKER

ok we seamed of solved the description problem

the only thing left is the total tax and combining totals now.

any suggestions why they be not working in the auth---php file and working fine in the tax.php file?

im going to poke around to see what i can find
Can I get your most recent version of both auth--php and tax.php please?
Avatar of Johnny

ASKER

http://www.openspaceconcepts.com/openspace/proccess_auth-dot-net.txt

<?php
$tax_rate="7.0";
$Safe_Purchase_Price="199.00";
$Calc_Tax_Total=(($Safe_Purchase_Price/100) * $tax_rate);
$tax = round($Calc_Tax_Total,2);
$subTaxTotal = ($Safe_Purchase_Price + $tax);

    $x_description = "yes-Electronic Safe Purchase - 1.19 cu. ft. Electronic Safe";
    $x_amount=$subTaxTotal;
?>
Playing with Safe_Purchase_Price info
Description: <?=$x_description?>  
Item Amount : <?=$Safe_Purchase_Price?>  
Tax Rate:<?=$tax_rate?>  
Tax Calc:<?=$Calc_Tax_Total?>  
Tax Amount : <?=$tax?>  
Tax included - Total Amount : <?=$subTaxTotal?>  
Total Amount : <?=$x_amount?>  
http://www.openspaceconcepts.com/openspace/proccess_auth-dot-net.txt this file doesn't have the description fix in it.

It looks like the code also contains the $subTotal,  $tax, and $subTaxTotal which could be causing your calculation errors.

I suspect that it is having problems due to the use of the same variable names for all the products calculations.

Noticed Something:
            $x_amount.=$subTaxTotal;
That is adding strings together
It should be:
            $x_amount+=$subTaxTotal;

I'll just throw that fix in there. I don't know if it will work quite yet but $x_amount at least should be the right number now.
if (!empty($items)){
 
        if (strstr($items, "Loft")) {
        $subTotal = $Loft_Price;
        $tax = round(($subTotal / 100) * $tax_rate,2);
        $subTaxTotal = $subTotal + $tax;
        
            $x_description .= " Loft Bed Rental ( Wittenberg ONLY) - Space-saving comfortable loft bed <br>";
            $x_amount+=$subTaxTotal;
        }
 
        if (strstr($items, "MicroFridge")) {
        $subTotal = $MicroFridge_Price;
        $tax = round(($subTotal / 100) * $tax_rate,2);
        $subTaxTotal = $subTotal + $tax;
 
            $x_description .= " MicroFridge Rental - Compact 2 door fridge and freezer with attached microwave <br>";
            $x_amount+=$subTaxTotal;
        }
        
        if (strstr($items, "Safe Rental")) {
        $subTotal = $Safe_Rental;
        $tax = round(($subTotal / 100) * $tax_rate,2);
        $subTaxTotal = $subTotal + $tax;
            $x_description .= " Electronic Safe Rental - 1.19 cu. ft. Electronic Safe <br>";
            $x_amount+=$subTaxTotal;
        }
 
        if (strstr($items, "Safe Purchase")) {
        $subTotal = $Safe_Purchase_Price;
        $tax = round(($subTotal / 100) * $tax_rate,2);
        $subTaxTotal = $subTotal + $tax;
            $x_description .= " Electronic Safe Purchase - 1.19 cu. ft. Electronic Safe <br>";
            $x_amount+=$subTaxTotal;
        }
 
} else {
        $x_description = "error: no items found - didnt capture posted item";
        $x_amount=$subTaxTotal;
}

Open in new window

Avatar of Johnny

ASKER

think i found the problem but haven't a clue how to fix it..

if (strstr($items, "Safe Purchase")) {
$tax_rate="7.0";
$Safe_Purchase_Price="199.00";
$item_amount=$Safe_Purchase_Price;
$Calc_Tax_Total=(($Safe_Purchase_Price/100) * $tax_rate);
$tax = round($Calc_Tax_Total,2);
$subTaxTotal = ($Safe_Purchase_Price + $tax);
    $x_amount = ($x_amount + $subTaxTotal);
    $x_description .= " Electronic Safe Purchase - 1.19 cu. ft. Electronic Safe
";
        }

that works fine..its due to the tax and safe purchase fields not being defined inside the if statement.. there not passing right
commenting out the tax and safe lines break the calculations
I think you fixes something without realizing how you fixed it. It was this line that I believe fixed it:
    $x_amount = ($x_amount + $subTaxTotal);

which is the same as:
            $x_amount+=$subTaxTotal; // +=

where you used to have
            $x_amount.=$subTaxTotal; // .=


And as for...
$tax_rate="7.0";
$Safe_Purchase_Price="199.00";

As long as you defined those before in the script and that they still are the expected value, you don't need to define them again in each if statement.

Try the code I posted above yours, that should do the trick (if added to the entire script in place of the original)
Avatar of Johnny

ASKER

its the current one now sorry forgot to upload it..

http://www.openspaceconcepts.com/openspace/proccess_auth-dot-net.txt
Looks like here is the problem as well:

In the script below
$sc (an array) is never defined

so all those
      $Loft_Price=$sc['Loft_Rental_Wittenberg'];
      $Safe_Rental=$sc['Safe_Rental_Wittenberg'];
      define("Safe_Purchase_Price",$sc['Safe_Purchase_Wittenberg']);
      $MicroFridge_Price=$sc['MicroFridge_Rental_Wittenberg'];
are returning NULL or 0 in this case
switch($_POST['School'])
{
    case "Wittenberg University":
     define("tax_rate","7.0");
     $tax_area="OH";
      $Loft_Price=$sc['Loft_Rental_Wittenberg'];
      $Safe_Rental=$sc['Safe_Rental_Wittenberg'];
      define("Safe_Purchase_Price",$sc['Safe_Purchase_Wittenberg']);
      $MicroFridge_Price=$sc['MicroFridge_Rental_Wittenberg'];
 
    case "University of Louisville":
    $tax_rate="6.0";
    $tax_area="KY";
      $Safe_Rental=$sc['Safe_Rental_Louisville'];
      $Safe_Purchase_Price=$sc['Safe_Purchase_Louisville'];
      $MicroFridge_Price=$sc['MicroFridge_Rental_Louisville'];
 
    case "West Liberty University":
     $tax_rate="0.000";
     $tax_area="WV";
      $Safe_Rental=$sc['Safe_Rental_West_Liberty'];
      $Safe_Purchase_Price=$sc['Safe_Purchase_West_Liberty'];
      $MicroFridge_Price=$sc['MicroFridge_Rental_West_Liberty'];
 
    default:
     $tax_rate="0.000";
}

Open in new window

Avatar of Johnny

ASKER

i was trying to define the vars to see if that was the problem i have corrected that ..

please check now...as its the current broke one...

the sc vars are pulled in from a file one the server (config)
heres the file as an include

  $sc['Loft_Rental_Wittenberg'] = '$175.00';
  $sc['Safe_Rental_Wittenberg'] = '$89.00';
  $sc['Safe_Purchase_Wittenberg'] = '$199.00';
  $sc['Safe_Rental_West_Liberty'] = '$89.00';
  $sc['Safe_Purchase_West_Liberty'] = '$199.00';
  $sc['Safe_Rental_Louisville'] = '$89.00';
  $sc['Safe_Purchase_Louisville'] = '$199.00';
  $sc['MicroFridge_Rental_Wittenberg'] = '$185.00';
  $sc['MicroFridge_Rental_West_Liberty'] = '$185.00';
  $sc['MicroFridge_Rental_Louisville'] = '$185.00';
Avatar of Johnny

ASKER

im gonna take a 5 min break as im stepping on your toes here...

the current file is the one with all the updates and things you have changed..

again thank you ever so much
Avatar of Johnny

ASKER

       if (strstr($items, "Safe Purchase")) {
        //$tax_rate="7.0";
          $Safe_Purchase_Price="199.00";
        $subTotal = $Safe_Purchase_Price;
        $tax = round(($subTotal / 100) * $tax_rate,2);
        $subTaxTotal = $subTotal + $tax;
            $x_description .= " Electronic Safe Purchase - 1.19 cu. ft. Electronic Safe
";
            $x_amount+=$subTaxTotal;
        }

if i comment out the price=199.00 it breaks..
and heres a odd thing
the tax is being read from the sc array(taken from vars via a included file) and works fine. it just wont pass the price var correctly.
i don't see any syntax problems with the lines in the include file nor in the auth php file.
Avatar of Johnny

ASKER

no the tax is defined in the auth file..so how do i get the sc array to work then..as that seams to be the problem

i have them defined in the web site all over the place. but here they dont work
Avatar of Johnny

ASKER

$subTotal = $Safe_Purchase_Price;
this reads fine and assigns the price.
trying to do
$tax = round(($subTotal / 100) * $tax_rate,2);
breaks unless you put the price in place of subtotal.
so it being an array sc problem is not correct as i did

 $Safe_Purchase_Wittenberg = '$699.00';
and it did no different it still didn't calc the values till i uncomment out the price line inside the if statement.
it passes the value so far then dies
just my luck to break it

maybe a rewrite is in order a different approach to assigning the values for each school?
i did notice a logic problem ill never get a list of item prices as we cant list them out for each item picked... maybe we have to break it down to each item picked then check for school price then print each via one line discrip/price fields then calc the values to show tax and final price.


i have to mow tomorrow(i own a lawn care company) so i cant work on this tomorrow till late around this time..and maybe over weekend too
ill try again in a little bit to see if we got any farther
also do you want me to open another question as this is getting deep now and outside the problem as we found another problem on top of the org one i had.


you said that
$Safe_Purchase_Price = "$199.00";
in the sc array

obviously it's the "$" (in $199.00) that is messing it up

Personally I would set the sc array values to not have a currency on them and just add them in when you need them (like on the form with prices on it)

Your script already uses something to remove the "$" from something or other

I suggest creating a function to strip it for you (I did it for you)

Use:
$subTotal = stripsign($Safe_Purchase_Price);
in place of:
$subTotal = $Safe_Purchase_Price;

Repeat for the others and include the function below somewhere in the script before that section at least.
<?php
function stripsign($curentvalue){
  if (substr($curentvalue, 0,1) == "$") {
  	$newvalue = substr($curentvalue,1);
  	return $newvalue;
  }else{
  	return $curentvalue;
  }
}
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of musicmasteria
musicmasteria

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Johnny

ASKER

it works now thank you
Avatar of Johnny

ASKER

if you want another question ill be happy to post one..so you can get more points as i believe we went beyond the org problem.
No problem Pern.

I guess we did get a little off topic there lol.

I'll leave it up to you if you want to open another question for more points. It's got to be a really creative question though... 2+2=? maybe lol

If you need anything else, I'd be happy to try my best to help.

~Musicmasteria :)