Sum in php does not work

Asked

Viewed 316 times

-3

Good morning, I have the following problem: I want to add the initial evaluation with the final evaluation and the result appear on the screen but always zero, where I am failing?

inserir a descrição da imagem aqui

<th>
    <div class="input-field col s12">
        <input id="AvInicial" type="text" class="validate"
               autocomplete="off" name="AvInicial">
        <label for="avinicial"></label>
    </div>
</th>
<th>
    <div class="input-field col s12">
        <input id="Meta" type="text" class="validate" autocomplete="off"
               name="Meta">
        <label for="meta"></label>
    </div>
</th>
<th>
    <div class="input-field col s12">
        <input id="AvIntercalar" type="text" class="validate"
               autocomplete="off" name="AvIntercalar">
        <label for="avintercalar"></label>
    </div>
</th>
<th>
    <div class="input-field col s12">
        <input id="AvFinal" type="text" class="validate" autocomplete="off"
               name="AvFinal">
        <label for="avfinal"></label>
    </div>
</th>
<th>
    <div class="input-field col s12">
        <?
            $a = $_GET['avinicial'];
            $b = $_GET['avfinal'];
              echo $a + $b;
        ?>
    </div>
</th>
  • var_dump the variables $a and $b to ensure that both are populated and integer

  • Give an echo separately in the variables to see if the values are coming.

  • @Diegovieira Fiz as I said and really the values are not coming.

  • Are you sending this data by GET even? It wouldn’t be via POST?

  • @Kayobruno tried with POST and nothing gave, in research I saw that should be with GET

  • Friend do the following: echo '<pre>'; print_r( $_GET ); die; This will show all values within $_GET, and show us what "printou".

  • @Kayobruno was thinking and nothing appears. Ta always thinking and not the rest of the table shows.

  • of an intval($a) + intval($b)

  • checks if your div is not with display:None

  • 1

    I think you are giving error, but your php may be configured not to show. try replacing the following lines with. $a = isset($_GET['avinicial'])? $_GET['avinicial']:0; $b = isset($_GET['avfinal'])? $_GET['avfinal']:0;

  • @Marcosbrinner nothing has changed, thank you so much for your help anyway!

  • add these lines at the beginning of your code to see if there are any errors

  • ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(E_ALL);

  • Are you even sending these values via $_GET? Post your html code. full so we can help.

  • Dude the names of the fields are different from the names you are trying to catch via GET: Avinicial != avinicial

  • @Kayobruno I don’t need the Avintercalar for this sum is only the Avinicial and Avfinal

  • @DavidVinicius &#xA; $nrutente = $_POST['NrUtente'];&#xA; echo $nrutente;&#xA;&#xA; $avinicial = $_POST['AvInicial'];&#xA; $meta = $_POST['Meta'];&#xA; $avintercalar = $_POST['AvIntercalar']; $avfinal = $_POST['Avfinal']; $datastart = $_POST['Datastart']; $enddate = $_POST['Enddate'];

  • @Vilelavilela ai you are receiving, what I think may be occurring is that you are not doing the form Submit, at least in the code that showed I have not seen any kind of Action that makes the Submit of this form.

  • @Diegovieira then as he advises to change the code so as to place a Ubmit?

  • 1

    first make sure the code is between the <form> (your code) </form> tags. You can put <button type="Submit">SEND</button>. by clicking this button it will send your form.

  • Besides the names of the fields are different, you didn’t give a Ubmit, just trying to add values that were not set. Gives a search in GET and POST form examples in PHP. This will help you a little.

  • well in that case you could just make some in javascript instead of php, it would be much faster

Show 17 more comments

1 answer

1

This is a basic example with 2 fields based on your form, try to use as an example to do with others.

<form action="">
    <table>
         <th>
            <div class="input-field col s12">
                <input id="AvInicial" type="text" class="validate"
                    autocomplete="off" name="AvInicial">
                <label for="avinicial">campo 1</label>
            </div>
        </th>            
        <th>
            <div class="input-field col s12">

                <label for="avfinal"> campo 4</label>
                <input id="Avfinal" type="text" class="validate"
                    autocomplete="off" name="Avfinal">
            </div>
        </th>
        <th>
            <div class="input-field col s12">
                <?php
                $a = isset($_GET['AvInicial']) ? $_GET['AvInicial'] : 0;
                $b = isset($_GET['Avfinal']) ? $_GET['Avfinal'] : 0;
                echo $a + $b;
                ?>

            </div>
        </th>
        <th>
            <button type="submit">Enviar</button>
        </th>
  • tbm I think he forgot the form tags

  • What’s happening is that you’re recording the whole page of that button.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.