Jump to content


Photo

SIMPLE: Array variables not being passed in foreach() statement


  • Please log in to reply
5 replies to this topic

#1 intech

intech
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 01 September 2006 - 01:04 PM

These foreach() statements have always thrown me for a loop...

I have a simple contact us form with a series of checkboxes where users can request notifications by different formats. They could have 1,2 or any number of boxes checked.

Here is my FORM code:

<input type="checkbox" name="some_info[]" value="Website Development" />DVD	
<input type="checkbox" name="some_info[]" value="Network Solutions" />Email
<input type="checkbox" name="some_info[]" value="Computer Upgrades/Repairs" />Newsletter

And here is my foreach() statement:

foreach($_POST['some_info'] as $some_info) {
	    $info = ". $some_info .";
}

What I get in the email is only the last selection formatted like the following:

Media requested: . Newsletter .

Not all variables are being passed...

My gratitude ahead of time...

#2 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 01 September 2006 - 01:16 PM

echo "<pre>";
print_r($_POST['some_info']);
echo "</pre>";
foreach($_POST['some_info'] as $some_info) {
	    $info = ". $it_info .";
}

try this, check if all data is posted properly or not.
hth
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#3 intech

intech
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 01 September 2006 - 01:32 PM

my line...
$info = ". $it_info .";
Should read...
$info = ". $some_info .";

(But still same problem)

Yep all variables are printed to screen with your debug code...

#4 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 01 September 2006 - 01:34 PM

change the assignment operator to .= instead of just =

#5 intech

intech
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 01 September 2006 - 01:39 PM

Now we're getting some where...

Changed my line to the following:

$info .= ". $some_info .";

It does pass all checkbox values to the email now, but I now get the dreaded error:

Notice: Undefined variable: info



#6 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 01 September 2006 - 01:48 PM

add
$info = '';
before your loop.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users