medprogress Posted January 16, 2008 Share Posted January 16, 2008 Hi, We have a script that does simple mathematical calculations (addition) which we use to provide our clients with an instant quote for my services. I am trying to expand that script to do an additional task -- (A+B+C) x D . Our current script only does (A+B+C). I can't get it to work, here is how it looks: Link to the page: http://medprogress.net/mail/mail_customize.php (note: website is still under heavy constructions) The form aspect in question is where customers input "Number of Mail pieces" and I would like that to be the "D" in my (A+B+C) x D equation. PHP calculations script: // TURN ON ERROR PRINTING IF NEEDED ini_set ('display_errors', 1); error_reporting (E_ALL); // SET VARIABLES FOR QUOTE NUMBER GENERATION $time = time(); $qn = rand(1, 99); $quote_num = $time . ' ' . $qn; // CALCULATE PACKAGE PRICE AND SELECTION If ( !empty($package) ) { switch ($package) { case "Internal": $package_price = 0; break; case "External": $package_price = 0; break; } } Else { $package = ""; $package_price = 0; } // CALCULATE ADD-ONS If ( !empty($addon1) ) { $addon1_price = 0.14; } Else { $addon1_price = 0; $addon1 = ""; } If ( !empty($addon2) ) { $addon2_price = 0.10; } Else { $addon2_price = 0; $addon2 = ""; } If ( !empty($addon3) ) { $addon3_price = 0.13; } Else { $addon3_price = 0; $addon3 = ""; } If ( !empty($addon4) ) { $addon4_price = .30; } Else { $addon4_price = 0; $addon4 = ""; } // CALCULATE MAINTENANCE COSTS If ( !empty($maintenance) ) { switch ($maintenance) { case "Postcard": $maintenance_price = 1.00; break; case "Newsletter": $maintenance_price = 1.10; break; } } Else { $maintenance = ""; $maintenance_price = 0; } $amount = $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price * 10000; (This is were i'm stuck) $total = $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price; If ($total > 0) { $select = "yes"; } Else { $select = "no"; } $downpayment = $total / 2; $total = number_format ($total, 2); $downpayment = number_format ($downpayment, 2); $eitems = ""; $items = ""; Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 16, 2008 Share Posted January 16, 2008 try adding a () ex. $amount =( $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price )* 10000; so after adding all the numbers it will them multiply to a given number all the operation inside the () will be the first to be executed Quote Link to comment Share on other sites More sharing options...
medprogress Posted January 16, 2008 Author Share Posted January 16, 2008 Thanks for the reply Ive added () and it does not affect the result. Just to expand on my question -- I want the number that is put into form field "Number of Mail Pieces" to be multiplied by [ ( $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price ) ]. Hope that clarifies it a bit more. Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 16, 2008 Share Posted January 16, 2008 $amount =( $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price )* 10000; i still dont fully understand im basing my answer on that code heres what your code does. add all this $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price then multiply by 1000.... is that right? Quote Link to comment Share on other sites More sharing options...
medprogress Posted January 16, 2008 Author Share Posted January 16, 2008 Close, but not the multiplication part. I don't want (a+b+c) be to multiply by 1000, i want the (a+b+c) be multiplied by the number a customer inputs into the form. So if a customer puts in "500", that is the number i want (a+b+c) be multiplied by. Quote Link to comment Share on other sites More sharing options...
KrisNz Posted January 16, 2008 Share Posted January 16, 2008 How are you retrieving said number? I don't see any reference to $_POST Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 16, 2008 Share Posted January 16, 2008 are asking if how to use do that so the user can input numbers? Quote Link to comment Share on other sites More sharing options...
medprogress Posted January 17, 2008 Author Share Posted January 17, 2008 Thats exactly it KrisNz, I don't have a reference and I would like help with that. teng84, essentially yes, I want them to put in a number they desire. And on the PHP script, I want the number they put in to be the multiplier. Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 17, 2008 Share Posted January 17, 2008 <a href="http://w3schools.com/php/php_post.asp">read this is what you need to know </a> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <meta name="generator" content="PSPad editor, www.pspad.com"> <title></title> </head> <body> <form action=" " method="post"> Enter price: <input type="text" name="price" /> <input type="submit" /> </form> </body> </html> <?php if(isset($_POST['price'])){ if(is_numeric(_POST['price'])){ // TURN ON ERROR PRINTING IF NEEDED ini_set ('display_errors', 1); error_reporting (E_ALL); // SET VARIABLES FOR QUOTE NUMBER GENERATION $time = time(); $qn = rand(1, 99); $quote_num = $time . ' ' . $qn; // CALCULATE PACKAGE PRICE AND SELECTION If ( !empty($package) ) { switch ($package) { case "Internal": $package_price = 0; break; case "External": $package_price = 0; break; } } Else { $package = ""; $package_price = 0; } // CALCULATE ADD-ONS If ( !empty($addon1) ) { $addon1_price = 0.14; } Else { $addon1_price = 0; $addon1 = ""; } If ( !empty($addon2) ) { $addon2_price = 0.10; } Else { $addon2_price = 0; $addon2 = ""; } If ( !empty($addon3) ) { $addon3_price = 0.13; } Else { $addon3_price = 0; $addon3 = ""; } If ( !empty($addon4) ) { $addon4_price = .30; } Else { $addon4_price = 0; $addon4 = ""; } // CALCULATE MAINTENANCE COSTS If ( !empty($maintenance) ) { switch ($maintenance) { case "Postcard": $maintenance_price = 1.00; break; case "Newsletter": $maintenance_price = 1.10; break; } } Else { $maintenance = ""; $maintenance_price = 0; } $amount = $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price * 10000; (This is were i'm stuck) $total = $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price; If ($total > 0) { $select = "yes"; } Else { $select = "no"; } $downpayment = $total / 2; $total = number_format ($total, 2); $downpayment = number_format ($downpayment, 2); $eitems = ""; $items = ""; }else{ echo 'invalid input'; } } ?> note not tested i dont have php in my machine now i just type that in note pad Quote Link to comment 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.