View Full Version : loops with queries and forms

05-25-2004, 01:06 AM
i have a system set up where u can select from 1-40 players to add to each team on this site, and depending on the selection of 1-40, it loops out that many groups of textboxes with their names being `player1` for the first one and `player2` for the second one etc.... but when i go to make the loop that inserts the info into the databases separately for each player, i cant figure out what to use for the number after player on $_POST.... like i tried $_POST['player$num'] with the below code and it just outputs the playernumber and not the info inputted in the textbox named player#.........

$college = $_POST['college'];
$con = mysql_connect("localhost","user","pass");
$numItems = $_POST['select'];
for ( $i = 0; $i < $numItems; $i++ ) {
$num = $i+1;
$name = $_POST['name$num'];
$speed = $_POST['speed$num'];
$position = $_POST['position$num'];
$sql = "INSERT INTO `players` (`college_id`,`name`,`height`,`weight`,`speed`,`position`,`player_id`) VALUES ('$college','$name','$height','$weight','$speed','$position','')";
mysql_query($sql) or die("ERROR: ".mysql_error());

05-25-2004, 01:39 AM

need to be

$_POST['name' . $num]