I want to add new values in php array by html form. I wrote something like following in php:
$b=array();
$b[]=$_POST['unos'];
and something like this in html:
<form action="?" method="post">
<input type="number" name="unos" id="unos">
</form>
And that code do the job, but only for one value. In other words, I am asking how to import more than one value in array. I add value="3"
in html input form, but that does not works, of course, or it is just one part of the answer. How to tell php to allow adding more than one value in array via html form?
UPDATE:
I want to import more values in one input field, that would be separated with "," for example, or whatever convention is.
UPDATE:
<?php
$unos=array();
$unos[]=$_POST['unos'];
$rezultat=count($unos); /*number of n's*/
$zbir=array_sum($unos); /*total sum of n's*/
$av=$zbir/$rezultat; /*average value of n's*/
echo "average value is $av</br>";
}
?>
<form action="?" method="post">
<input type="number" name="unos" id="unos">
<input type="submit" value="Submit">
</form>
The code calculate average value of n's. I am beginner and just want to know how to add values of arrays by user via html.The reason I wanted to know how one can do that in 1 input file is because I do not want to limit number of values with number of input fields. I want make that user can add values as many as he want. Sorry, my English is not perfect.
$_POST['unos']into an array, the rest of your code looks correct. However, you also need to check whether$_POST['submit']is set, so you can tell whether you're printing the initial form or responding to the submission.