esiason14 Posted April 2, 2006 Share Posted April 2, 2006 I'm trying to make a simple form that will allow users to select certain baseball players to add to their profiles.Here is part of my form:[code]<form name="myplayers" method="post" action="insertmyplayers.php"><?phpecho "<TABLE width=\"100%\" border=\"0\">";echo "<TD align=\"center\" valign=\"top\"><TABLE width=\"100%\" border=\"0\"><TD><div align=\"center\"><divalign=\"center\"><h1>Catcher</div></h1>";$query = "SELECT ps.*,p.*, t.* FROM playerstats ps INNER JOIN ( players p INNER JOIN mlbteams t ON t.mlbteam_id = p.mlbteam_id ) ON ps.player_id = p.player_id AND ps.year = 2005 AND position_id = 1 ORDER by lname";$result = mysql_query($query);while ($row = mysql_fetch_array($result)) { $pid = $row['player_id']; $lname = $row['lname']; $fname = $row['fname'];echo "<input name=\"myplayers[];\" type=\"checkbox\" value=\"$pid\">$lname, $fname<br>";}echo "</TD></TABLE></TD>";[/code]My post page that executes the insert query:[code]foreach($_POST['player_id'] AS $newp) { $sql = "INSERT INTO myplayers (player_id) VALUES ($newp)"; mysql_query ($sql) or die(mysql_error()); }?>[/code]I keep getting this error on submission:[code]Warning: Invalid argument supplied for foreach() in[/code]If I select 5 players for the form page. This is what the array looks like: print_r($_POST);[code]Array ( [myplayers] => Array ( [0] => 676 [1] => 677 [2] => 1078 [3] => 1080 [4] => 1089 [5] => 1090 ) [player_id] => )[/code]Any idea what I'm messing up Link to comment https://forums.phpfreaks.com/topic/6371-foreach-error-in-checkbox-form/ Share on other sites More sharing options...
esiason14 Posted April 2, 2006 Author Share Posted April 2, 2006 Figured it out Link to comment https://forums.phpfreaks.com/topic/6371-foreach-error-in-checkbox-form/#findComment-23056 Share on other sites More sharing options...
kenrbnsn Posted April 2, 2006 Share Posted April 2, 2006 Please post your solution so that people reading your post who have the same problem can learn.Ken Link to comment https://forums.phpfreaks.com/topic/6371-foreach-error-in-checkbox-form/#findComment-23077 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.