<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Number Report</title>
</head>
<body>
<h1>Enter Numbers</h1>
<form method="POST" action="">
<label for="numbers">Enter numbers (comma-separated):</label><br>
<input type="text" id="numbers" name="numbers" required><br><br>
<input type="submit" value="Submit">
</form>
<?php
include('includes/header.php');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Step 2: Process the form data
$numbersInput = $_POST['numbers'];
$numbersArray = explode(',', $numbersInput);
$evenCount = 0;
$oddCount = 0;
$sum = 0;
echo "<h2>Brian's Number Report</h2>";
echo "<table border='1'>
<tr>
<th>Number</th>
<th>Type</th>
</tr>";
// Step 3: Loop through the numbers and perform decisions
foreach ($numbersArray as $number) {
$number = trim($number); // Trim whitespace
if (is_numeric($number)) {
$sum += $number; // Accumulate sum
if ($number % 2 == 0) {
$evenCount++;
echo "<tr><td>$number</td><td>Even</td></tr>";
} else {
$oddCount++;
echo "<tr><td>$number</td><td>Odd</td></tr>";
}
} else {
echo "<tr><td>$number</td><td>Invalid</td></tr>";
}
}
echo "</table>";
echo "<h3>Total Even Numbers: $evenCount</h3>";
echo "<h3>Total Odd Numbers: $oddCount</h3>";
echo "<h3>Sum of All Numbers: $sum</h3>";
}
include('includes/footer.php');
?>
</body>
</html>