Why does not display the result? And the error does not write.

index.php

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Массивы</title> </head> <body> <form action='calc.php' method='post'> <input type='number' name='x'> <select name='op'> <option value='+'>+</option> <option value='-'>-</option> <option value='*'>*</option> <option value='/'>/</option> </select> <input type='number' name='y'> <input type='submit' value='='> </form> </body> </html> 

handler.php

 <?php function calc($a, $b, $op){ switch ($op){ case '+': return $a + $b; break; case '-': return $a - $b; break; case '*': return $a * $b; break; case '/': return $a / $b; break; default: return null; } } assert(4==calc(2,2, '+')); assert(6==calc(2,3, '*')); assert(3==calc(5,2, '-')); ?> 

calc.php

 <?php require __DIR__ . '/handler.php'; $res = calc($_POST['x'], $POST['y'], $POST['op']); echo $res; ?> 

    1 answer 1

    you have an error with $ POST ['y'], $ POST ['op'] variables - underscore is missing, and since in the script itself, by default, the operation is "null", then there is no error as a result, but nothing needs to be output. Ie most likely a blank screen