#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Location
    Atlanta, GA
    Posts
    269
    Rep Power
    14

    problem with loops


    I have a form that lets users select multiple topics to post on. On submission from selecting their topics to post on, the next page will draw out the forms for them to fill in.

    so far so good.

    Now the next page (after they submit their filled in forms) will make sure the info is correct (or there at all) and then it will insert the values into a database one form at a time.

    Here is where the problem lies.

    I can grab all the values from all the forms using HTTP_POST_VARS....but I am stuck on how to insert values from one form, then grab the values from the next form, insert them, and so on. The way I am grabbing them allows me to get all of the values for ALL of the forms. I am not sure how to split the passed values into "sections" to then be inserted.

    I am trying to use loops to do this (obviously) but I am stuck on how to get this done. I know there are 5 values per form, so I am using a for loop.

    for (i=0; i<5; i++)

    but, I am using:

    list($key, $value) = each($HTTP_POST_VARS))

    to grab the values from the HTTP_POST_VARS...

    The problem is that once I have grabbed all of the values and I want to put them in the database....the names are the same, so the values are all messed up.

    Also, I am not sure how many topics the user has selected, therefore I am not sure of the number to stop at (in the for loop).

    Any elp would be appreciated.

    I hope this is the correct forum to post in.

    Thanks in advance.
  2. #2
  3. Mobbing Gangster
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Sep 2001
    Location
    "Best City" 2002 and 2003- Melbourne, Australia
    Posts
    4,912
    Rep Power
    33
    >>The way I am grabbing them allows me to get all of the values for ALL of the forms.

    Sorry to disapponit you, trops, but you will end up with those values that were in the form which was sumitted. See, even though you can have several forms in one html file, user can only press one submit button, and thus only one form will count as having any values at all. So you should re-work your system of getting information, and post it in the correct forum (php, that is).

    Good luck.
    And you know I mean that.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Location
    Atlanta, GA
    Posts
    269
    Rep Power
    14

    I figured it out


    I figured out how to do it.

    I find out the count for how many checkboxes were marked. then I drew the form for each checkbox. I also included a counter when I was drawing the forms, so each form would have fields title, post, but when they were drawn out they would become title1, post1, and so forth.

    Then when I wanted to submit them I pulled the info out in a for loop, using:

    for($i=0; $i < $count; $i++)
    {
    $title = $HTTP_POST_VARS['title'.$i];
    ...
    ..

    }

    And it works like a charm..I can have multiple forms, and multiple insert statements all with the correct information.

    so there.
  6. #4
  7. Mobbing Gangster
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Sep 2001
    Location
    "Best City" 2002 and 2003- Melbourne, Australia
    Posts
    4,912
    Rep Power
    33
    >>I can have multiple forms, and multiple insert statements all with the correct information.

    So then you could show an example where two different forms will pass all of it's values to the script when only one is submited, right? Something like
    Code:
    <form name=form1>
    <input name=blah value=bleh><br>
    <input type=submit value=go>
    </form>
    
    <form name=form2>
    <input name=foo value=bar><br>
    <input type=submit value=go>
    </form>
    And you know I mean that.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Location
    Atlanta, GA
    Posts
    269
    Rep Power
    14

    kinda.


    i have it looking like this.

    <form name="formname">

    <input name="title1" value="whatever">
    <input name="body1" value="whatever">

    <input name="title2" value="whatever">
    <input name="body2" value="whatever">
    </form>


    And then when I loop throughthe values, I grab each by name with the i in the for loop tagged onto the end of the name.

    thats how I did it.
  10. #6
  11. Mobbing Gangster
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Sep 2001
    Location
    "Best City" 2002 and 2003- Melbourne, Australia
    Posts
    4,912
    Rep Power
    33
    If you read my post carefullly, you'll see that I was talking about having several format being submitted with one submit button.
    In your original post you said:
    >>how to insert values from one form, then grab the values from
    >>the next form, insert them, and so on.
    which makes me think more then one form.

    Anyway, I'm glad you've solved your problem.
    And you know I mean that.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Location
    Atlanta, GA
    Posts
    269
    Rep Power
    14

    sorry about that.


    We had a bit of a miscommunication....but alas the problem is solved....let the celebration begin...(time to watch the stanley cup).

    Thanks again.

IMN logo majestic logo threadwatch logo seochat tools logo