1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

switch function throwing off my code

Discussion in 'PHP' started by mnymkr, Apr 29, 2007.

  1. #1
    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):
     
    mnymkr, Apr 29, 2007 IP
  2. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #2
    well, for one, you're not picking up the form $_POST value in the php and assigning it to a variable
     
    frankcow, Apr 29, 2007 IP
  3. mnymkr

    mnymkr Well-Known Member

    Messages:
    2,328
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #3
    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...
     
    mnymkr, Apr 29, 2007 IP
  4. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    manilodisan, Apr 29, 2007 IP
  5. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #5
    try adding
    
    $calc = $_POST['calc'];
    
    PHP:
    before
    
    if($calc != null)
    
    PHP:
     
    frankcow, Apr 30, 2007 IP