CaseyC1 Posted December 8, 2007 Share Posted December 8, 2007 I am a retired programmer (Fortran, ASM, Cobol, etc.) attempting to muddle my way through some php code. The piece of code that I am modifying is an HTML form and a php script that handles the inputs from that form and stores them in a SQL database. I added additional input boxes to the form and added the appropriate code to the script to process this input. So far, so good. My next attemp was to use these variables and in a short piece of code to calculate a markup constant and then multiply cost times constant and come up with a retail value. Sound like a piece of cake, but I hit the proverbial brick wall. I cannot get the filtering for the markup value to work (in the example below the value is definitely greater than 10, but it kicks out in the first compare), and the simple multiplication code yields a value of zero. I have added a ton of print statements to the code to trace the variables, and they all look good. Below is the section of code, followed by the output from the print statements. Could some kind soul please look at this and tell me what I'm doing wrong? Thank you...... SECTION OF CODE $cost2 = $record["my_price"]; $retail2 = $record["catalog_price"]; $markup2 = $record["markup"]; echo "before IF test<br>"; print_r ($markup2 ."<br>"); print_r ($retail2 ."<br>"); print_r ($cost2 ."<br>"); echo "during IF test<br>"; if ($markup2 == 0.00) { if($retail2 < 10.00) { echo $retail2 ." =1<br>"; $markup2 = 3.0; } if ($retail2 >=10.00 && $retail2 <15.00) { echo $retail2 ." =2<br>"; $markup2 = 2.7; } if ($retail2 >= 15.00 && $retail2 < 20.00) { echo $retail2 ." =3<br>"; $markup2 = 2.5; } if ($retail2 >= 20.00 && $retail2 < 25.00) { echo $retail2 ." =4<br>"; $markup2 = 2.3; } if ($retail2 >= 25.00 && $retail2 < 35.00) { echo $retail2 ." =5<br>"; $markup2 = 2.1; } if ($retail2 >= 35.00 && $retail2 < 40.00) { echo $retail2 ." =6<br>"; $markup = 2.0; } if($retail2 >= 40.00) { echo $retail2 ." =7<br>"; $markup2 = 1.8; } } echo "before multiply<br>"; print_r ($markup2 ."<br>"); print_r ($cost2 ."<br>"); $price2 = $cost2*$markup2; echo "after multiply<br>"; print_r ($markup2 ."<br>"); print_r ($price2 ."<br>"); print_r ($retail2 ."<br>"); print_r ($cost2 ."<br>"); DEBUG PRINT OUT before IF test '0.00' '39.95' '13.96' during IF test '39.95' =1 before multiply 3 '13.96' after multiply 3 0 '39.95' '13.96' Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Not sure where you set your $record variable, but here you are making everything strings instead of using integers $cost2 = $record["my_price"]; $retail2 = $record["catalog_price"]; $markup2 = $record["markup"]; If my_price, catalog_price and markup are numbers ,remove the double quotes or use INT to convert them in the string. Quote Link to comment Share on other sites More sharing options...
CaseyC1 Posted December 8, 2007 Author Share Posted December 8, 2007 Thank you for your reply, revraz. The values are defined in the db as decimal 10,2. Just prior to my added code the following statements set the variables: $record["my_price"] = $db->mySQLSafe($_POST['my_price']); $record["catalog_price"] = $db->mySQLSafe($_POST['catalog_price']); $record["markup"] = $db->mySQLSafe($_POST['markup']); I tried your suggestion by removing the quotes, and by doing that I did not print any values at all when executing the code. They were all 0. I then tried to convert the variables to reals by using "floatval" but that yielded the same result. Quote Link to comment Share on other sites More sharing options...
CaseyC1 Posted December 9, 2007 Author Share Posted December 9, 2007 Just an update......since making the changes suggested by revraz, I looked at the code that sets the variables: $record["my_price"] = $db->mySQLSafe($_POST['my_price']); $record["catalog_price"] = $db->mySQLSafe($_POST['catalog_price']); $record["markup"] = $db->mySQLSafe($_POST['markup']); I then removed the double quotes from the three variables and ran the code again. Now I am getting the original values again in the debug printout. Frustrating to say the least. Could the problem be in the way these values are input? Like I said in an earlier post, they are defined in the db as decimal 10,2 and input through a HTML form. Input code is as follows: <tr> <td width="25%" class="tdText"><strong><?php echo "MarkUp Factor:";?></strong></td> <td><input name="markup" value="<?php if(isset($results[0]['markup'])) echo $results[0]['markup']; ?>" type="text" class="textbox" size="10" /></td> Since the input is set as "text" does this mean I have to convert the input to a number????? 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.