Why does it jump directly to Pepsi Cola and not the selected option?

0

I have the following Index:

<html>
<head>
    <title>Productos</title>
</head>
<body>
    <h2>Productos</h2>
    <hr>
<form method="post" action="productos.php">
    Elige tu producto:
<select name="listings">
     <option value="Seleccionar">Seleccionar</option>
     <option value="cocacola" <?php if($listings1 == "cocacola") print('selected="selected"'); ?> >Coca Cola</option>
     <option value="fanta" <?php if($listings2 == "fanta") print('selected="selected"'); ?> >Fanta </option>
     <option value="pepsi"  <?php if($listings3 == "pepsi") print('selected="selected"'); ?> >Pepsi</option>
</select>
<br>
<br>
Unidades:
<br>
<input type="text" name="Unidades">
<br>
<input type="submit" name="Aceptar">
</form>
</body>
</html>

and the products.php file with the following source code:

<?php

$value=$_POST["listings"];
$listings1=$_POST['cocacola'];
$listings2=$_POST['fanta'];
$listings3=$_POST['pepsi'];

$precio_pepsi=25;
$precio_fanta=20;
$precio_coca=30;


switch ($listings) { 
    case 
    $listings3:
        echo "Has pedido ".$_REQUEST['Unidades']." unidades de Pepsi Cola";
        echo "<br>";
            echo "Precio total: ". $precio_pepsi * $_REQUEST['Unidades'];
        break;

    case 
    $listings2:
        echo "Has pedido ".$_REQUEST['Unidades']." unidades de Fanta Naranja";
        echo "<br>";
            echo "Precio total: ". $precio_fanta * $_REQUEST['Unidades'];
        break;

    case 
    $listings1:
        echo "Has pedido ".$_REQUEST['Unidades']." unidades de Coca Cola";
        echo "<br>";
            echo "Precio total: ". $precio_coca * $_REQUEST['Unidades'];
        break;

}
?> 

the question is seleciono fanta but always the result I get coca cola why does this usually happen? as I see it seems that it does not take the variables it is appreciated help in advance.

    
asked by Juan Carlos Villamizar Alvarez 09.11.2018 в 03:45
source

2 answers

0

Try this solution!

?php

$valoresListings=$_POST["listings"];
/*
$listings1=$_POST["cocacola"];
$listings2=$_POST["fanta"];
$listings3=$_POST["pepsi"];
*/

$precio_pepsi=25;
$precio_fanta=20;
$precio_coca=30;

switch ($valoresListings) { 

case 'cocacola':

    echo "Has pedido ".$_REQUEST['Unidades']." unidades de Coca Cola";
    echo "<br>";
        echo "Precio total: ". $precio_coca * $_REQUEST['Unidades'];
    break;

case 'fanta':

    echo "Has pedido ".$_REQUEST['Unidades']." unidades de Fanta Naranja";
    echo "<br>";
        echo "Precio total: ". $precio_fanta * $_REQUEST['Unidades'];
break;

case 'pepsi':
    echo "Has pedido ".$_REQUEST['Unidades']." unidades de Pepsi Cola";
    echo "<br>";
        echo "Precio total: ". $precio_pepsi * $_REQUEST['Unidades'];
    break;

default:
    echo "Valor no encontrado";
break;
}

?> 

The variable $ valuesListings saves me the value it brings from "listings". and then according to the value the respective cases are programmed.

    
answered by 09.11.2018 / 04:42
source
0

Check the $ listings variable, with which the Switch starts.

echo "Valor de listing".listings;
switch ($listings) { 

The variable $ listings is not bringing any value.

    
answered by 09.11.2018 в 04:23