user7067590 - 1 year ago 94
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>";
``````

``````<?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>
``````
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download