I am making a script which is going to add together a bunch of inputs. I am almost there, but when testing the script i seem to get the alert: Notice: Undefined index: number in C:\xampp\htdocs\Archers.php on line 25. Even though I have declared it earlier and even when using it now. The script is below. Thanks in advance.
<html>
<head>
</head>
<body>
<form method="post">
Enter how many values you would like to enter:
<input type="number" name="number">
<input type="submit" name="submit">
</form>
<?php
$number = 0;
$result = 0;
if (isset($_POST["submit"])){
$number = $_POST['number'];
$x = 0;
echo "<form method=\"post\">";
while ($x != $number) {
echo "Enter score: <input type=\"text\" name=\"".'a'.$x."\"><br>";
$x = $x + 1;
}
echo "<input type=\"submit\" name=\"submit2\"></form>";
}
if (isset($_POST["submit2"])){
$y = 0;
$number = $_POST['number'];
while ($y != $number){
$value = $_POST["a".$y];
$result = $result + $value;
$y = $y + 1;
}
echo $result;
}
?>
</body>
</html>