tmfl Posted December 23, 2010 Share Posted December 23, 2010 Hi, I'm having problems retrieving the values from a form posting without getting a warning My form records playername, hours played and minutes played <li id="input1" style="margin-bottom:4px;" class="clonedInput"> Name: <select name="player[1][userid]" id="player[1][userid]" class="playerInput" style="width: 7em;" > <option value=""></option> <?php while($row = mysql_fetch_array($sql)) { echo '<option value="'.stripslashes($row['userid']).'">'.stripslashes($row['name']).'</option>'; } mysql_data_seek($sql,0); ?> </select> <select name="player[1][hours]" id="player[1][hours]"> <option value="">Hours</option> <option value=""></option> <?php for($x = 0; $x <= 23; $x++ ) { echo '<option value="'.$x.'">'.$x.'</option>'; } ?> </select> <select name="player[1][minutes]" id="player[1][minutes]"> <option value="">Minutes</option> <option value=""></option> <?php for($y = 15; $y <= 59; $y+=15) { echo '<option value="'.$y.'">'.$y.'</option>'; } ?> </select> </li> I use some javascript to create new players as necessary so every player has a userid, hours, minutes played... After posting the query string looks like this /cLeagueHandler.php?player[1][userid]=1&player[1][hours]=3&player[1][minutes]=15&player[2][userid]=3&player[2][hours]=6&player[2][minutes]=45&submit=Save+Points player1 userid = 1 hours = 3 minutes = 15 player2....... The code i'm using to access the values is print_r ($_GET); // test display form values foreach ($_GET as $key => $value) { echo '<br/>'.$key.'<br/> '; foreach ($value as $iKey => $iValue) { // Line 72 foreach ($iValue as $xKey => $xValue) { echo " The $xKey for Player $iValue is $xValue <br/>"; } } } The above code displays Array ( [player] => Array ( [1] => Array ( [userid] => 1 [hours] => 3 [minutes] => 15 ) [2] => Array ( [userid] => 3 [hours] => 6 [minutes] => 45 ) ) [submit] => Save Points ) player The userid for Player Array is 1 The hours for Player Array is 3 The minutes for Player Array is 15 The userid for Player Array is 3 The hours for Player Array is 6 The minutes for Player Array is 45 submit Warning: Invalid argument supplied for foreach() in .................cLeagueHandler.php on line 72 Line 72 is foreach ($value as $iKey => $iValue) { If anyone could help me with this it would be great appreciated.......I want to be able to build and sql string to Insert a players id, hours, minutes into a database......(obviously not incl the submit value!) Maybe this is not even the best way of approaching this.....I'm quiet new to PHP so apologies if this is long winded...I'm trying to give as much info as possible.... thanks in advance tmfl Quote Link to comment https://forums.phpfreaks.com/topic/222442-retrieving-form-values-from-multi-dimensional-array/ Share on other sites More sharing options...
dreamwest Posted December 23, 2010 Share Posted December 23, 2010 Look down the bottom of this page for multi arrays http://www.wizecho.com/nav=php&s=array Quote Link to comment https://forums.phpfreaks.com/topic/222442-retrieving-form-values-from-multi-dimensional-array/#findComment-1150565 Share on other sites More sharing options...
sasa Posted December 23, 2010 Share Posted December 23, 2010 $_GET['submit'] is nut array try print_r ($_GET); // test display form values foreach ($_GET as $key => $value) { echo '<br/>'.$key.'<br/> '; if($key != 'submit'){ foreach ($value as $iKey => $iValue) { // Line 72 foreach ($iValue as $xKey => $xValue) { echo " The $xKey for Player $iValue is $xValue <br/>"; } } } } Quote Link to comment https://forums.phpfreaks.com/topic/222442-retrieving-form-values-from-multi-dimensional-array/#findComment-1150605 Share on other sites More sharing options...
tmfl Posted December 28, 2010 Author Share Posted December 28, 2010 Worked a treat thanks! Now on to the next stage!...storing the hours and minutes....not sure i know whats the best way to approach this using the above code....reckon i'll be posting again! thanks again.... Quote Link to comment https://forums.phpfreaks.com/topic/222442-retrieving-form-values-from-multi-dimensional-array/#findComment-1152295 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.