Php undefinded variable

0

Hello this form worked for me, I do not know what happens now.

<form action="cliente_ingresado.php" method="post" >
<div>
    <label for="identificacion" >Identificación:  </label> &nbsp;
    <input type="text" name="identificacion" id="identificacion" required="required"/>
</div>

<div>
    <label for="nombre" >Nombre: </label>&nbsp;
    <input type="text" name="nombre" id="nombre" required="required"/>
</div>

<div>
    <label for="direccion">Dirección: </label>&nbsp;
    <input type="text" name="direccion" id="direccion" />
</div>

<div>
    <label for="telefono">Teléfono: </label>&nbsp;
    <input type="text" id="telefono" name="telefono"/>
</div>

<div>
    <label for="correo">Correo: </label>&nbsp;
    <input type="email" id="correo" name="correo"/>
</div>

<!--<div>
    <label for="sexo">Sexo: </label>&nbsp;
    <input type="text" id="sexo" name="sexo"/>
</div> -->

<div>
    <label id="label1" name='sexo2'>Turno </label> &nbsp;    
    <input type='radio' name='Masculino' value='M'  checked> Masculino &nbsp;
    <input type='radio' name='Femenino' value='F' > Femenino<br><br>
</div>

<div>
    <label for="estado_civil">Estado Civil:  </label>&nbsp;
    <input type="text" id="estado_civil" name="estado_civil"/>
</div>

<div class="button">
    <button type="submit" name="submit" onclick="validarFormulario()">Guardar</button> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

    <button type="button">Limpiar</button>
</div>

When I pass the values to the other page, I get that the variables are not defined

if(isset($_POST['identificacion']) &&
        isset($_POST['nombre']) && 
        isset($_POST['direccion']) && 
        isset($_POST['telefono']) && 
        isset($_POST['correo']) &&
        //isset($_POST['sexo']) &&
        isset($_POST['estado_civil']))
    {             
    
asked by Jhon Hernández 09.06.2018 в 21:59
source

2 answers

1

What happens is that to use isset with multiple variables, the operator && is not used if not that the same variables are separated only by commas; then your code should be:

if(isset($_POST['identificacion'], $_POST['nombre'], $_POST['direccion'], $_POST['telefono'], $_POST['correo'], $_POST['sexo'], $_POST['estado_civil']))
    {
         echo "exito";  
    }

In the same way you do not need to redeclare the isset function, you just have to type it once

EXAMPLE:

$num1 = "hi";
$num2 = "bye";

if(isset($num1, $num2)){
  echo "exito";
}else{
  echo "fallo";
}
    
answered by 09.06.2018 / 22:05
source
0

You can not put comments within the IF's unless they are in the Final

if ( isset($_POST['identificacion']) && isset($_POST['nombre']) && isset($_POST['direccion']) && isset($_POST['telefono']) && isset($_POST['correo']) && isset($_POST['estado_civil']) // Coment ) { 
       // Code Function
    }
    
answered by 09.06.2018 в 22:54