| | |
foreach help PLEASE
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2008
Posts: 19
Reputation:
Solved Threads: 0
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());
}
$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.
![]() |
Similar Threads
- how to convert typed dataset to untyped dataset??? (C#)
- using foreach with multi-dimensional arrays (PHP)
- Multidimensional array list & foreach? (C#)
- Problem with foreach when using linking (PHP)
Other Threads in the PHP Forum
- Previous Thread: Weird issue: code breaking site in IE6
- Next Thread: Can I specify who can access certain links on a web page?
| Thread Tools | Search this Thread |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions simple sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube





