user7067590 user7067590 - 1 month ago 11
PHP Question

The average of three numbers

I have a Form.html and Form.php file. My Form.html file has 3 text input boxes asking a user to enter a numeric number in each one. I would like to echo the average number after the user clicks submit. This is what I have so far, although after I click submit the average number is "0"

// The Average of Numbers
$number1 = ['number3'];
$number2 = ['number3'];
$number3 = ['number3'];

// How Many Numbers are in Our Set
$numbersInSet = 3;

// Get the Sum of the Numbers
$average = $sum / $numbersInSet;

echo "The average of the three numbers you entered is<b> $average<p>";

Answer
<?php
// The Average of Numbers
$number1 = isset($_POST['number1']);
$number2 = isset($_POST['number2']);
$number3 = isset($_POST['number3']);

// How Many Numbers are in Our Set
$numbersInSet = 3;

if(is_numeric($number1) &&is_numeric($number2)&&is_numeric($number3)){
$sum=$number1+$number2+$number3;

// Get the Sum of the Numbers
$average = $sum / $numbersInSet;
echo "The average of the three numbers you entered is<b> $average<p>";
}

?>

<form method="post">
<input type="text" name="number1" />
<input type="text" name="number2" />
<input type="text" name="number3" />
<input type="submit">
</form>