samedi 24 septembre 2016

2 checkboxes for ball's area and circumference

I have an html file with form with 2 checboxes in it, and I wanted to calculate the area and circumference of ball, but the form doesn't return any value...

HTML file:

 <!DOCTYPE html>
<html>
<head>
<title>Ball</title>
<meta charset="UTF-8">
</head>
<body>
<form action="test.php" method="post">

Enter radius: <br><br>
<input type="text" name="radius"> <br><br>

    Area:
<input type="checkbox" name="check_list[]" value="value 1"><br>
    Circumference:
<input type="checkbox" name="check_list[]" value="value 2"><br>

<button type="submit">Calculate</button>
</form>

</body>
</html>

And the PHP file (I used foreach loop):

<?php
$radius = $_POST['radius'];

if(!empty($_POST['check_list'])) {
    foreach($_POST['check_list'] as $check) {

            if ($check == "0")
            {
                $result1 = 4*3.14*($radius*$radius);
                echo "Area: " . $result1."<br>";

            }
            if ($check == "1")
            {
                $result2 = 4/3*3.14*($radius*$radius*$radius);
                echo "Circumference: " . $result2 . "<br>";             
            }
}
?>

Why it doesn't work? What am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire