Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 3rd, 2002, 01:00 AM
trops trops is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Location: Atlanta, GA
Posts: 269 trops User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 22 sec
Reputation Power: 8
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.
__________________
trops.
Databake Software

Reply With Quote
  #2  
Old June 8th, 2002, 02:30 PM
AlCapone's Avatar
AlCapone AlCapone is offline
Mobbing Gangster
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Sep 2001
Location: "Best City" 2002 and 2003- Melbourne, Australia
Posts: 4,913 AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 36 m 31 sec
Reputation Power: 18
Send a message via ICQ to AlCapone Send a message via AIM to AlCapone Send a message via Yahoo to AlCapone
>>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.

Reply With Quote
  #3  
Old June 8th, 2002, 05:02 PM
trops trops is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Location: Atlanta, GA
Posts: 269 trops User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 22 sec
Reputation Power: 8
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.

Reply With Quote
  #4  
Old June 8th, 2002, 05:26 PM
AlCapone's Avatar
AlCapone AlCapone is offline
Mobbing Gangster
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Sep 2001
Location: "Best City" 2002 and 2003- Melbourne, Australia
Posts: 4,913 AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 36 m 31 sec
Reputation Power: 18
Send a message via ICQ to AlCapone Send a message via AIM to AlCapone Send a message via Yahoo to AlCapone
>>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>

Reply With Quote
  #5  
Old June 8th, 2002, 06:48 PM
trops trops is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Location: Atlanta, GA
Posts: 269 trops User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 22 sec
Reputation Power: 8
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.

Reply With Quote
  #6  
Old June 8th, 2002, 07:10 PM
AlCapone's Avatar
AlCapone AlCapone is offline
Mobbing Gangster
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Sep 2001
Location: "Best City" 2002 and 2003- Melbourne, Australia
Posts: 4,913 AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 36 m 31 sec
Reputation Power: 18
Send a message via ICQ to AlCapone Send a message via AIM to AlCapone Send a message via Yahoo to AlCapone
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.

Reply With Quote
  #7  
Old June 8th, 2002, 07:29 PM
trops trops is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Location: Atlanta, GA
Posts: 269 trops User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 22 sec
Reputation Power: 8
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > problem with loops


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway