Access Array of _POSTed values - gotta be simple...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ACRMIKE
Forum Newbie
Posts: 7
Joined: Sun Jul 05, 2009 4:41 pm

Access Array of _POSTed values - gotta be simple...

Post by ACRMIKE »

I just can't figure this out. It's got to be simple, but I'm missing something.
Without dumping out a bunch of code, here is the issue:

This is what I'm getting from the print_r ($_POST) below;
Array (
[user_votes] => Array ( [0] => 77 [1] => 22 [2] => 55 )
[sponsor_id] => Array ( [0] => 10 [1] => 20 [2] => 30 )
[doSave] => Save
)


if($_POST['doSave'] == 'Save'){
print_r($_POST);
// now i am trying to grab the values of user_votes and sponsor_id by iterating through the array so I can use them in an insert statement. $count is equal to three. the loop is working but I can't figure out how to grab the values from the _POST. Some of the things I've tried to no avail (with just $userVotes) are shown in the snippit below. Can anyone please help with this? :banghead: Thanks. Mike

for($i=0;$i<$count;$i++){
$userVotes = '$_POST[user_votes';
$userVotes = '$_POST[$user_votes';
$userVotes = '$_POST[$user_votes[$i]';
$userVotes = '$_POST[$user_votes[$i][0]';
$userVotes = '$_POST[$user_votes[$i][1]';
$userVotes = '$_POST[user_votes]';
$userVotes = '$_POST[$user_votes]';
$userVotes = '$_POST[$user_votes[$i]]';
$userVotes = '$_POST[$user_votes[$i][0]]';
$userVotes = '$_POST[$user_votes[$i][1]]';
}
}
jmetzen
Forum Newbie
Posts: 5
Joined: Sat Feb 13, 2010 1:16 pm

Re: Access Array of _POSTed values - gotta be simple...

Post by jmetzen »

Hello,

I could be mistaken, but I think you're looking for something like:

Code: Select all

 
$userVotes = $_POST["user_votes"][$i];
 
Let me know if that works.
ACRMIKE
Forum Newbie
Posts: 7
Joined: Sun Jul 05, 2009 4:41 pm

Re: Access Array of _POSTed values - gotta be simple...

Post by ACRMIKE »

oh man, THANK YOU SO MUCH!!!
that was it!! have a great night.
mike
Post Reply