because when I put it on any day, it releases me CORRECT

0
<!DOCTYPE html>
<html>
<?php
$num1=0; $num2=0; $num3=0; $num4="";
if (isset($_POST["btnCalcular"])) {
    $num1=$_POST["txtnum1"];
    $num2=$_POST["txtnum2"];
    $num3=$_POST["txtnum3"];
    $num4=$_POST["txtnum4"];    

    switch ($num1) {
        case '1':
            if($num2>0 && $num2<32){
                $num4="CORRECTO";
             }              
            break;
        case '2':
            if($num2%4==0 && $num2%400==0){
                $num4="CORRECTO";
            }           
            break;
        case '3':
            if($num2>0 && $num2<32){
                $num4="CORRECTO";
            }
            break;
        case '4':
            if($num2>0 && $num2<31){
                $num4="CORRECTO";
            }
            break;
        case '5':
            if($num2>0 && $num2<32){
                $num4="CORRECTO";
            }
            break;
        case '6':
            if($num2>0 && $num2<31){
                $num4="CORRECTO";
            }
            break;                  
        case '7':
            if($num2>0 && $num2<32){
                $num4="CORRECTO";
            }
            break;
        case '8':
            if($num2>0 && $num2<32){
                $num4="CORRECTO";
            }
            break;  
        case '9':
            if($num2>0 && $num2<32){
                $num4="CORRECTO";
            }
            break;
        case '10':
            if($num2>0 && $num2<31){
                $num4="CORRECTO";
             }
            break;
        case '11':
            if($num2>0 && $num2<31){
                $num4="CORRECTO";
            }
            break;
        case '12':
            if($num2>0 && $num2<32){
                $num4="CORRECTO";
            }
            break;                              
        default:
            $num4="INCORRECTO";
            break;
            }
    }
?>
<head>
    <title></title>
</head>
<body>
    <form method="post" action="7.php"><table>
    <tr>
    <td>Mes</td>
    <td><input type="text" name="txtnum1" id="txtnum1" value="<?=$num1?>"></td>
</tr>
<tr>
    <td>Dia</td>
    <td><input type="text" name="txtnum2" id="txtnum2" value="<?=$num2?>"></td>
</tr>
<tr>
    <td>Año</td>
    <td><input type="text" name="txtnum3" id="txtnum3" value="<?=$num3?>"></td>
</tr>
<tr>
    <td>Respuesta</td>
    <td><input type="text" name="txtnum4" id="txtnum4" value="<?=$num4?>"></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="btnCalcular" id="btnCalcular" value="Calcular"></td>
</tr>
</table>
</form>
</body>
</html>
    
asked by santiago 06.12.2017 в 23:26
source

2 answers

0

to me if the code worked.

I send you a simpler one that also worked for me.

Variables $ num1 and $ num2 must be numeric.

// Definimos el máximo de días de cada mes
$dias_arr=[31,28,31,30,31,30,31,31,30,31,30,31];

// Si el mes ($num1) es entre 1 y 12 entramos avalidar el día ($num2)
if ( $num1=1 && $num1<=12 ) {

// Validamos si el dia ($num2) esta en el rango de días del mes ($num1)
    if ( $num2>=1 && $num2<=$dias_arr[$num1] ) {

// Si cumple las condiciones anteriores es correcto el día
        $num4="CORRECTO";

    }
}

Greetings.

    
answered by 07.12.2017 в 03:23
0

If $num4 can only take two values: CORRECT and INCORRECT, then you should initialize it as "INCORRECT".

if (isset($_POST["btnCalcular"])) {
    $num1=$_POST["txtnum1"];
    $num2=$_POST["txtnum2"];
    $num3=$_POST["txtnum3"];
    $num4='INCORRECTO';   

    switch ($num1) {


    }

}

Since if the month is between 1 and 12, it will enter a loop of the type

case '3':
  if($num2>0 && $num2<32){
     $num4="CORRECTO";
  }
break;

Then if $num2 = 33 , then $num4 will not be altered and therefore keep the value that comes from $num4=$_POST["txtnum4"]; and that is not what you are looking for

With the change I'm telling you, the answer will start being WRONG and will only change if the conditions are met for it to be correct.

    
answered by 07.12.2017 в 18:29