What's new

PHP Fatal error: Uncaught Error: Call to undefined function

marleybob

Honorary Poster
Joined
Aug 18, 2015
Posts
362
Reaction
51
Points
194
Age
29
error.PNG


Ano po kaya mali dito laging error function undefined.


Code:


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<table>
<tr>
<td>Enter a:<input type="text" name="n"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="submit"></td>
</tr>
</table>

</form>

</div>
<?php
$n = "";
$sum = 0;
$even = array();
$odd = array();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$num = $_POST["n"];

for($i = 1; $i <= $num; $i++){
$sum += $i;
if($i % 2 == 0){
array_push($even, $i);
}else{
array_push($odd, $i);
}
}
?>

<div>
<table>
<tr>
<td><?php echo "Sum: ".$sum?></td>
</tr>
<tr>
<td><?php
echo "Even: ";
foreach ($even as $x) {
echo $x."|";
}
?></td>
</tr>
<tr>
<td><?php
echo "Odd: ";
foreach ($odd as $x) {
echo $x."|";
}
?></td>
</tr>
<tr>
<td><?php
$average = calAverage($even);
echo "Average for even: ".$average;
?></td>
</tr>
</table>
</div>
<?php

function calAverage($x){

$average = array_sum($x)/count($x);
echo $average;
}
?>
<?php }?>

</body>
</html>
 

Attachments

Similar threads

Back
Top