foreach help PLEASE

Reply

Join Date: Jan 2008
Posts: 19
Reputation: Morty222 is an unknown quantity at this point 
Solved Threads: 0
Morty222 Morty222 is offline Offline
Newbie Poster

foreach help PLEASE

 
0
  #1
Oct 6th, 2008
I ask the user how many players are on their roster and they select the answer from a drop down menu, click submit and it generates 1 roster spot for the amout of players they selected. Here is this code:

$players comes from the number they selected above.

$players = $_SESSION['players'];
$i=1;
while($i<=$players){
echo "<tr><td><input name=player[$i][fname] type=text size=15/></td><td><input name=player[$i][lname] type=text size=15 /></td><td><input name=player[$i][jersey] type=text size=5 /></td><td><input name=player[$i][dob] type=text size=7 /></td><td><input name=player[$i][address] type=text size=15 /></td><td><input name=player[$i][city] type=text size=15 /></td><td><input name=player[$i][zipcode] type=text size=5 /></td><td><input name=player[$i][position] type=text size=15 /></td></tr>";
$i++;
}

Wwhen I do a submit to add each player to the database using a foreach loop all the data in every field says Array, not what they typed in.

I either have something wrong in the fields above or my foreach is messed up. Here is my foreach to add them to the DB:

$teamID = $_GET['teamID'];

foreach($key as $c=> $value){

mysql_query("insert into tbl_rosters (teamID, fname, lname, jersey, dob, address, city, zipcode, position) VALUES ('$teamID', '".$_POST['fname']."','".$_POST['lname']."', '".$_POST['jersey']."', '".$_POST['dob']."', '".$_POST['address']."', '".$_POST['city']."', '".$_POST['zipcode']."', '".$_POST['position']."') ") or die(mysql_error());

}
Last edited by Morty222; Oct 6th, 2008 at 11:45 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 828
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 136
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: foreach help PLEASE

 
0
  #2
Oct 7th, 2008
I think you may need to use something like $_POST[$key]['fname'] or $value['fname']

The latter should be the right one, because it's the current array in the loop.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC