PHP - Notice: Undefined index Select Form

0

I'm trying to do a simple PHP processing and I get the following error:

Notice: Undefined index: payment1 in C: \ xampp \ htdocs \ actividadangel2 \ activity.php on line 38

Notice: Undefined index: payment1 in C: \ xampp \ htdocs \ actividadangel2 \ activity.php on line 45

        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
          <td><img src="001-corn.png"></td>
          <td>Maíz</td>
          <td><input action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" type="number" name="valorneto" placeholder="Introduzca el monto"></td>
          <td>     
            <select id="metodo_de_pago" name="pago1">
              <option value="E">Efectivo</option>
              <option value="T">Tarjeta</option>
            </select>
            
          </td>
          <td>
            <?php
              if ($_POST["pago1"]=="E") 
              {
                $valorneto = ($_POST['valorneto']);
                $sumaE = (int)$valorneto + ((((int)$valorneto * 16))/100); #Nota: Se solventó el problema de "non-numeric value" con (int). 
                echo $sumaE ." " ."Petros";           
              } 
             else {
                if ($_POST["pago1"]=="T") 
                {
                  $valorneto = ($_POST['valorneto']);
                  $sumaT = (int)$valorneto+((((int)$valorneto)*(10))/100);
                  echo $sumaT;
                }
              }         
               if (!empty($_POST['valorneto'])) {
                  echo " ";
                }
            ?>        
          </td> 
        </form> 
      </tr>
       <tr>
          <td style="align-content: center;">
            <input type="submit" name=" operar">           
          </td>
        </tr>

The lines in question are:

  

38 = if ($ _POST ["payment1"] == "E")
  45 = if ($ _POST ["payment1"] == "T")

    
asked by Angel Coronado Duno 06.11.2018 в 00:54
source

1 answer

0

In fact, it is not a serious error to be a notification or warning in this case "NOTICE", this is because "$ _POST [" payment1 "]" is not declared if not until after sending the form, you have Several options to solve this.

  • Edit php.ini of the server and set the error_reporting to not notify the NOTICE :

    error_reporting = E_ALL & ~E_NOTICE ; Notificar todos los errores excepto los NOTICE

  • Disable the NOTICE At the beginning of your file, that is, they will be deactivated only in this file at the time of execution. Using the function error_reporting()

    <?php error_reporting(E_ALL ^ E_NOTICE); // esto al principio de tu archivo

  • Another alternative is to execute your code portion only if the form was sent.

    <?php if(isset($_POST['submit'])){ if ($_POST["pago1"]=="E") { //aqui el resto de tu codigo...

  • answered by 06.11.2018 / 02:03
    source