• Math calculation PHP

    Arnold Member

    Ok everyone I made two different pages

        index.php
        test.php

    Index.php

    
    
    
    
    
     
    Your Population:



    and test.php

    
    
    
    
    You are protected from players with lower than  pop.
    You are protected from players with bigger than  pop.
    
    
    

    The problem I’m having at the moment is when I type in for example 100 into the form (index.php) the result doesn’t seem to show correctly in test.php. Seems like my GET and POST or echo’s are wrong somehow…

    cobusbo is offline View user’s profile Send private message

  • SapnaVishwas Member

    It seems you have mixed the $_POST and the echos a little.

    We use $_GET at the receiver page to acquire the value we sent with the form. The form sends the “pop” value.

    You can access it at test.php with $_POST[“pop”] or $_GET[“pop”] if the form’s action is GET instead of POST.

    So:

    At index.php you do not need to echo the $pop variable. Just use: value=””

    At test.php replace:

    $min = ($pop * 20 / 100);
    $max = ($pop * 100 / 20);
    

    with:

    $min = ($_GET["pop"] * 20 / 100);
    $max = ($_GET["pop"] * 100 / 20);
    

    and:

    You are protected from players with lower than  pop.
    You are protected from players with bigger than  pop.
    

    with:

    You are protected from players with lower than  pop.
    You are protected from players with bigger than  pop.
    
  • Ganesh Member

    A little more clarification as to why it’s not working as it is supposed to :

    
    
    
    
    
     
    Your Population:



    in your test.php variables from the form are submitted as GET , and as rgman already pointed out, you attempt to retrieve the value of POST vars … and those are empty

Viewing 2 reply threads
  • You must be logged in to reply to this topic.
en_USEnglish