Please help I am trying to collect data from a form with checkbox's.
This is a little complicatec but ill try to explain
The whole script is on one function. with case at the bottom of the page.ie#
switch ($op) {
case "wars":
wars();
break;
case "completegame":
completegame($gameid, $complete, $players);
break;
}
then I have the function completegame. Its too large from here so ill cut it down just to the bit you need
function completegame($gameid, $complete, $players)
{
global $hlpfile, $pntable;
if($complete)
{
foreach ( $players as $value )
{
echo "$players<br>\n"
}
}
elseif($gameid)
{
$result = mysql_query("SELECT id, g_map1, g_map2, g_league, g_date, g_ip, g_password, g_players FROM $pntable[wars_games] WHERE id='$gameid'");
while ( $a_row = mysql_fetch_array($result))
{
echo "<form action=\"admin.php\" method=\"\">"
."<input type=\"hidden\" name=\"op\" value=\"completegame\">"
."<input type=\"hidden\" name=\"complete\" value=\"complete\">"
."<input type=\"hidden\" name=\"gameid\" value=\"$a_row[id]\">"
."<table width=\"100%\"><tr><td width=\"160\">".GAMETYPE."</td><td><SELECT name=\"g_type\">";
$result2 = mysql_query( "SELECT gtype_id, gtype_name FROM $pntable[wars_leagues] ORDER by gtype_name ASC" );
while ( $a_row2 = mysql_fetch_row( $result2 ))
{
echo "<option value=\"$a_row2[0]\""; if ($a_row2[0] == $a_row[g_league]) echo "SELECTED";
echo ">$a_row2[1]\n";
}
echo "</SELECT></td></tr>"
listplayersbox( $gameid );
echo "<tr><td></td><td><input type=\"submit\" value=\"Submit\"></td></tr>"
."</table></form>";
}else{
OpenTable();
echo "<table width=\"100%\">"
."<tr><td width=\"90\" align =\"center\"><b>".DATE."</b></td><td width=\"90\" align =\"center\"><b>".OPPONENTS."</b></td><td width=\"90\" align =\"center\"><b>".GAMETYPE."</b></td><td width=\"90\" align =\"center\"><b>".SELECT."</b></td></tr>";
$result = mysql_query("SELECT id, g_opp_id, g_date, g_league FROM $pntable[wars_games] ORDER BY g_date DESC");
while ( $a_row = mysql_fetch_array( $result ))
{
echo "<tr><td width=\"90\" align =\"center\">".date("D j M H:i", $a_row[g_date])."</td><td width=\"90\" align =\"center\">";
listclan( $a_row[g_opp_id] );
echo "</td><td width=\"90\" align =\"center\">";
leaguetype( $a_row[g_league] );
echo "</td><td width=\"90\" align =\"center\"><a class=\"pn-normal\" href=\"admin.php?op=completegame&gameid=$a_row[id]\">".SELECT."</a></td></tr>";
}
echo "</table>";
CloseTable();
}
}
Now in the middle of the script is there is another function called listplayersbox. see below
function listplayersbox( $gameid )
{
global $pntable;
$players = mysql_query("SELECT uid, uname FROM $pntable[users] order by uname ASC");
while ( $a_row = mysql_fetch_row( $players ))
{
$result2 = mysql_query("SELECT game_id, player_id FROM $pntable[wars_players] where player_id='$a_row[0]' and game_id='$gameid'");
$row = mysql_fetch_row( $result2 );
if ($row){
echo "<tr><td>$a_row[1]</td><td><INPUT TYPE=\"CHECKBOX\" name=\"players[]\" value=\"$a_row[0]\" checked></td></tr>";
}else{
echo "<tr><td>$a_row[1]</td><td><INPUT TYPE=\"CHECKBOX\" name=\"players[]\" value=\"$a_row[0]\"></td></tr>";
}
}
}
So basically it first starts with the last else then goes to the $gameid then to the $complete. Up to complete it all works and I can view the source And I have neat checkboxes with there data in correct.
Now when I go to the last part of this function $complete all i am doing should be is looping through the $players but all i get is
Invalid argument supplied for foreach() in
I have tried it a number of ways. I just cant get the checkbox data. Is it because they are passed through a function.
I realy need this to work And i cant go no further until I do this bit.
Please help if you can
Lee Smith (Thanks)