Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2004

    Question Unanswered: Dynamic POST form variable retrieval


    I have a form which is made out of checkboxes and Option Dropdowns.

    These are set by the user in another part of the app.

    This works fine, except for retrieving the data for the next page.

    Usually the form would have set names which are easy to retrieve but in this case they are dynamically set.

    This means that there is a textbox named coid1, coid2, coid3 etc... depending on how many the user set up.

    I can select the criteria and do a num rows at the other end, that works fine except that this does not (obviously) work.

    PHP Code:

    $result=mysql_query("INSERT into tblwhatever (coid) VALUES ('$coid[$i]')"); 
    How can I do something like this?


  2. #2
    Join Date
    Apr 2005
    Baltimore, MD
    From your code it seems like you are just looping through the inputs and inserting them into the database?

    It may be easier for you to do something like this...
    first, give all of your inputs the same name and end the name with []. For example, you may want to name them all coid[].

    Then, in your php script...
    PHP Code:
    //since we added the [], $coid is now an array of coid form variables
    //we want to enquote each and join them all into one string, separated by commas
    $values "'" implode("','"$coid) . "'";
    $result=mysql_query("INSERT into tblwhatever (coid) VALUES ($values)"); 
    I'm pretty sure that will work, but the code may require a little bit of tweaking.

Posting Permissions

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