User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 397,751 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,585 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2984 | Replies: 4
Reply
Join Date: Oct 2004
Location: San Francisco, CA
Posts: 338
Reputation: paradox814 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

$_POST and arrays

  #1  
Jul 4th, 2005
I need to load a value from a recently posted page...

[php]for ($i=0; $i<10; $i++)
{
$_SESSION['someVar'][$i] = $_POST['someVar'][$i]
$_SESSION['anotherVar'][$i] = $_POST['anotherVar'][$i]
$_SESSION['yetAnotherVar'][$i] = $_POST['yetAnotherVar'][$i]
}[/php]

now the session part works just fine, but the $_POST part just blows up on me! How can I fix this? I want to keep the $_POST there, because I know I can just do $someVar[$i] and that will work but it's not what I want to do. I have seen a foreach loop and thought about that. But, would that keep all the variables tied together with the same index? I really dont want to use a foreach loop if I dont have to, but if thats what I need to use, then so be it.

Thanks!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: $_POST and arrays

  #2  
Jul 4th, 2005
Originally Posted by paradox814
[php]$_SESSION['someVar'][$i] = $_POST['someVar'][$i][/php]
$_POST['someVar'][$i] is not valid unless your 'someVar' FORM element is an array of checkboxes or you have multiple text fields with the same name. Normally, it would just be $_POST['someVar'].

Whether it is an array or not, you can just do this:
[PHP]
$_SESSION['someVar'] = $_POST['someVar'];
[/PHP]It does not matter whether 'someVar' is an array or not--the session var will still receive the value.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Join Date: Jan 2005
Location: Sheffield, UK
Posts: 294
Reputation: zippee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
zippee's Avatar
zippee zippee is offline Offline
Posting Whiz in Training

Re: $_POST and arrays

  #3  
Jul 5th, 2005
How about this?[PHP] $_SESSION['someVar'][$i] = $_POST['someVar'.$i] [/PHP]In this case, your form variables are someVar1, someVar2,...
Ecommerce-Web-Store.com Building Your e-Business.
Reply With Quote  
Join Date: Jul 2005
Posts: 10
Reputation: val542 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
val542 val542 is offline Offline
Newbie Poster

Re: $_POST and arrays

  #4  
Jul 5th, 2005
why not using define function!?
Reply With Quote  
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: $_POST and arrays

  #5  
Jul 5th, 2005
val542, your reply makes no sense. The define() function does not even apply to this scenario.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 3:24 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC