2016-10-25 55 views
-4

我有一個Form.html和Form.php文件。我的Form.html文件有3個文本輸入框,要求用戶在每個文件中輸入一個數字。我想在用戶點擊提交後回顯平均數。這是我到目前爲止,雖然經過我點擊提交的平均數量爲「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>"; 
+0

您沒有設置一個值'$ sum' –

+1

嘿哪裏是你的$總和 – Shibon

+0

' $ number1 = ['number3'];' 這是什麼?你應該編輯你的代碼。 –

回答

0
<?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> 
+0

您是否也沒有注意到'$ number#'變量都不是整數? –

+0

@Memor-X.感謝您的更正 – iCoders

+0

這完全按照計劃運作!謝謝! – user7067590