Hi , I want to lead in to this saying I am just learning this stuff. I thought I would code something I knew so I went with chemistry stuff. This code works great when I enter Ka values into a text box but when I try to use this switch for my radio buttons. I lose it.....any help would be great and any overall code improvements..... <html><head><title>Calculation Result</title></head> <body> <?php // moloarity calculation $neglog = $pH*-1; $hydronium = pow (10,$neglog); if($calc != null) { switch($calc) { case "aceticacid" : $Ka=2; break; case "ethanoicacid" : $Ka=100; break; case "boricacid" : $Ka=1000; break; } $result = (pow($hydronium,2)/$Ka) + $hydronium ; $resulta = (pow($hydronium,2)/$Ka) ; echo("Calculation result: $result"); $volume = 0.400; $moles = $result* $volume; ?> <form method = "post" action = "<?php echo $PHP_SELF;?>"> PH: <input type="text" name="pH" size="10"> Ka: <input type="radio" name="calc" value= "aceticacid">Acetic Acid <input type="radio" name="calc" value="ethanoicacid">Ethanoic Acid <input type="radio" name="calc" value="boricacid">Boric Acid <input type="submit" value="Calculate"> <input type="reset" value="Clear"> </form> Hydronium concentration: <?php echo number_format($hydronium, "6", ".", ","); ?><br /> Inital Molarity (no apprixmation): <?php echo number_format($result, "6", ".", ","); ?> <br /> Inital Molarity (neglect x): <?php echo number_format($resulta, "6", ".", ","); ?> <br /> moles required for <? echo $volume?> Liters of solution: <?php echo number_format($moles, "6", ".", ","); ?> <br /> </body></html> Code (markup):
im not sure if i see what you are talking about what do i need to change all i know is that i am copying a similar script that does something similar and if i take out the switch it works sorry very new to this...
if you only use 3 values(2, 100, 1000) than switch is ok but if you wanna expand your restrictions I suggest you to use if else statements. Here's some help: http://www.roscripts.com/Building_multiple_conditional_statements_in_PHP-49.html