PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

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 May 22nd, 2000, 10:05 PM
garrick garrick is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 3 garrick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi im a newbie trying to take the arrays day and band
into the (if month) script and then loop through arrays, inserting varibles into seperate records in a database, thus multiple records could be updated from one form.
Is the problem my syntax or am I leaving something important out.

<input type="hidden" name="day[]><br> <input type="text" name="band[]"><br>
<input type="hidden" name="day[]><br> <input type="text" name="band[]"><br>
<input type="hidden" name="day[]><br> <input type="text" name="band[]"><br>

<input type="submit" name="makemonth">

if ($makemonth) {
while (list ($day, $band) = each ($HTTP_POST_VARS)) {

insert day and band into database etc...

}
}

Reply With Quote
  #2  
Old May 23rd, 2000, 02:42 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan

while (list ($day, $band) = each ($HTTP_POST_VARS)) {
insert day and band into database etc...

}


actually you won't get the $day and $band in this way..

you should separate your field name and values from the formfield.

while (list ($name, $value) = each ($HTTP_POST_VARS)) {
#separate the name and value from the form field.
#get the name and values one by one.

print $name.":".$value;

}
so you can't get the $day, $band values in single row for insertion.

you should do this in a different way to insert this row.


probably you can try something like this.

$bands=$HTTP_POST_VARS[band];
$days=$HTTP_POST_VARS[day];


for($a=0;$a<count($bands);$a++){

$query="INSERT INTO tbl set day='$days[$a]',band='$bands[$a]'";

mysql_query($query,$connection);


}


<input type="hidden" name="day[]>

remember,, you are not passing any value through this field.

And also you are missing " thier.

<input type="hidden" name="day[]">





------------------
SR -
shiju.dreamcenter.net

"The fear of the LORD is the beginning of knowledge..."

[This message has been edited by Shiju Rajan (edited May 23, 2000).]

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > looping through array sent by form

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap