I have been trying to create a php script which takes any number from a text form, and puts it into an array. Then I want to loop through the array and output each number.
So far with some searching around on Google, I've come up with this piece of code. Unfortunatly it doesn't work. The strange thing is, I actually got it working at some point, but somehow the code wouldn't function anymore without actually changing anything in the script.
Can anyone help me complete this, I have my version which worked at some point but doesn't anymore.
(I know I should filter input but since this is just an exercise it doesn't really matter.)
<html>
<head>
<title>13.13</title>
<body>
<h2> Inputting numbers into array through form</h2>
<br>
<br>
<form>
<input type="text" name="number" />
<input type="button" value="submit" name="submit" />
</form>
<?php
session_start();
if (isset($_REQUEST['submit'])) {
$number = $_REQUEST['number'];
if (!isSet($_SESSION['number'])) {
$_SESSION['number'] = array();
}
array_push($_SESSION['number'], $number);
foreach($_SESSION['number'] as $key => $val) {
echo $key . ">" . $val;
}
}
?>
</body>
</html>