variables - PHP $_POST values
i have a little problem with storing the $_POST data, think i might be confusing myself a little.
So i have some data being posted from a loop, this data is posted as id and points, but each has a number to it so if three records are being posted we'll have
id1, id2, id3 points1, points2, points3
to collect. Now i'm using a for loop to go through the data and post it into two arrays to work with. The problem is When I want to store the data i have to use one of the names listed above ie id1 or id2. Here is my code
for($i = 0; i< $_POST['count']; i++){
//Order input data into an array
$inputid[$i] = $_POST['id1'];
}
Now the number part of the 'id' of the $_POST['id1'] has to be the same as $i in the for loop so it will increment as the loop does.
Thanks for the help and i hope i explained the question right.
Answer
Solution:
Why not name the inputs:
name="id[1]"
andname="points[1]"
so you'll have$_POST['id'][...]
and$_POST['points'][...]
arrays to work with?Reference: Variables From External Sources (specifically Example #3).
Answer
Solution:
Firstly, don't use POST variables in loops or anything else unless you've checked them out first to make sure they don't contain anything nasty.
You could try this within the loop:
Answer
Solution:
Answer
Solution:
Simply concatenate the string in the index:
Answer
Solution:
If I understand this question, there are already a known amount of inputs that are going to be posted, so I don't understand why you need a loop at all for adding them to the array. Why not do this:
than loop like this:
That should work
Answer
Solution:
if i am not going wrong you want the posted id same as the increment var $i try this out
Answer
Solution:
I think you can go for something like this:
Is this what you want?