Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post

    loops with queries and forms

    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#.........
    ----------------------------------
    PHP Code:
    <?php
    $college 
    $_POST['college'];
    $con mysql_connect("localhost","user","pass");
    mysql_select_db("condraft_pp",$con);
    $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());
    }
    ?>

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $_POST['name$num']

    need to be

    $_POST['name' . $num]
    or
    $_POST["name$num"];
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •