Home > Mobile >  If-else statement if theres no value input
If-else statement if theres no value input

Time:05-05

Im trying to handle error in my code, how do i if-else when there is no value on the input of user and the user calculates it?

<h1> Triangle</h1>
<div style="border:1px solid black">
<form action="triangle.php" method="get">
    Base: <input type="number" name="base"> meters
    <br>
    Height: <input type="number" name="height"> meters
    <br>
    <input type="submit" value="Calculate">
</form>
</div>

<?php
if (isset($_GET['base'])) {

$base1 = $_GET['base'];
$height1 = $_GET['height'];
$area = triangleArea($base1, $height1);
echo "Area is: " . $area;
}
?>

CodePudding user response:

You're already checking whether the base value exists or not. It looks like you need to also check whether the height value exists - so just add that into the isset function call:

if (isset($_GET['base'], $_GET['height'])) {
  • Related