Ask for data in php

-2

Dear good morning.

How can I request a data in php (after clicking on the submit button?).

I have the following initial formula where I ask for "Product Code", "Quantity" and the submit button.

<?php
header('Content-type: text/html; charset=utf-8');
$retVal = '
<html>
    <head>
        <style>
            body{
            background: #004B85;
            }
        </style>
        <form action="resultados.php" method="get">
            <center>
            <table border="3" bgcolor=white>
                <tr>
                    <td align= "right">
                        Código:
                    </td>
                    <td>
                        <input type="date" name="selCodigo" required="required"/>
                    </td>

                    <td align= "right">
                        Cantidad:
                    </td>
                    <td>
                        <input type="date" name="cantidad" required="required"/>
                    </td>
                </tr>
            </table>
            <input type="submit" value="Calcular">
            </center>
        </form>
    </head>
</html>';
echo $retVal;
?>

By clicking on the submint button, you execute the calculations but only a few products have several release percentages.

The code of the file resultados.php that I need to complete is more or less like this:

<?php
$selCodigo = $_GET(selCodigo);
$libera = mysql_query('SELECT porcentaje FROM liberaciones WHERE codigo = "'.$selCodigo.'" ;');
$numDatos = mysql_num_rows($libera);
switch (TRUE){
    case ($numDatos > 1):
        // (Esta es la parte que no se cómo haerlo)
        // El producto tiene "Varios" porcentajes de liberaciones
        // y debe desplegar (por ejemplo una ventana modal)
        // con los porcentajes de liberación para que el
        // usuario escoja.
        //
        // El 0.10 por ciento de los productos tienen este problema
        $porcenLibAdv = "El porcentaje que escoje el usuario";
    case ($numDatos == 1):
        // El producto solo tiene un único porcentaje liberatorio, aquí no hay problema.
        // El 9.9 por ciento de los productos tienen un valor liberatorio
        $liberaArray = mysql_fetch_array($libera);
        $porcenLibAdv = $liberaArray['porcentaje'];
    default:
        // No hay porcentaje liberatorio, aquí tampoco hay problema.
        // El 90 por ciento de los productos no tienen liberación
        $porcenLibAdv = 0;
}

$resultado = $valor * $porcenLibAdv;

?>

Is there a way to ask for that data in resultados.php? or necessarily the user has to enter it in inicial.php?

    
asked by Erick 21.06.2018 в 23:35
source

2 answers

0

To collect data sent through a <form> , depending on whether you used GET or POST, you have to ask if the value you have sent exists or not, and if it exists, you collect it in a variable.

$porcenLibAdv = null;

if (isset($_GET["porcenLibAdv"])) {
    $porcenLibAdv = $_GET["porcenLibAdv"];
} 

If you used POST, the same but $_POST["porcenLibAdv"]

And now that you have the value, you can use it as you like in your code.

    
answered by 21.06.2018 в 23:43
0

PHP provides a large number of predefined variables for all scripts. The variables represent everything from external variables to built-in environment variables, from the last error messages to the last headers recovered.

  • $ _ GET - HTTP GET variables
  • $ _ POST - HTTP POST Variables
  • $ _ FILES - HTTP file upload variables
  • $ _ REQUEST - HTTP Request Variables
  • $ _ SESSION - Session variables

You can visit the following link: PHP - predefined variables

If what you want is to insert the data directly in the url I recommend you Request: $ variablereceived = $ _ REQUEST ['namevariable'];

    
answered by 22.06.2018 в 00:34