Jump to content

PHP Array Help Please!


napsburypark

Recommended Posts

Hi Folks.

 

A quick question.

I am trying out the fcbkcomplete script which will be great on a new school website I am working on however when it sends the form field it sends it as select2[]

so if I were using the GET method I  see in the address bar

 

submit.php?select2[][email protected]

 

however when i try and capture the select2[] php just says 'array' 

 

Any ideas?

Thank you

Link to comment
https://forums.phpfreaks.com/topic/196413-php-array-help-please/
Share on other sites

actually I now have another little problem.

 

I need the form to send via PHPMAIL - I am using the following.

 

<?php

$to = $arr = $_GET['select2']; foreach( $arr as $a){ echo $a;};

$subject = $_REQUEST['Subject'] ;

$message = "This is an online form enquiry sent from the website.

 

Your Name:

".$_REQUEST['parent']."

 

Your Telephone:

".$_REQUEST['telephone']."

 

Your Message:

".$_REQUEST['message']."

 

 

This email was automatically generated. Thank You";

$from = $_REQUEST['email'] ;

$headers = "From: $from";

mail($to,$subject,$message,$headers);

echo "";

?>

 

but i get the following error now:

Warning: mail() expects parameter 1 to be string, array given in /home/marlb/public_html/About/form/submit1.php on line 33

 

Any ideas?

as prometheos said, $arr, or $_GET['select2[]'], both of these are array

if u dont know what is array, read http://php.net/manual/en/language.types.array.php

so, u access $arr[0] or $arr[0]

$arr= $_GET['select2[]'];

$to=$arr[0]; 

NOT the following

$to = $arr  <<< WRONG!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 

in the wrong case, u get this

$arr= array('something', 'something1', 'something');

 

in the right case

u get $arr='something';

Okay got it. Thank you I have this working now.

 

I have just one more query.

 

If the form submits more than one email address it will post the following:

 

submit.php?select2[][email protected]&select2[][email protected]

 

however PHPMail just sees this as to: [email protected]@email.com

 

how can I make the following code break those two email addresses up?

 

<?php
$arr = $_REQUEST['select2'];
foreach( $arr as $a){
}
?>								
<?php
$to=$arr[0]; 
$subject = $_REQUEST['Subject'] ;
$message = "This is an online form enquiry sent from the Website. The details of which are below.

Your Name:
".$_REQUEST['parent']."

Your Telephone:
".$_REQUEST['telephone']."

Your Message:
".$_REQUEST['message']."


This email was automatically generated. Thank You";
$from = $_REQUEST['email'] ;
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "";
?>

 

I know I am asking a lot but I am new to PHP and just need to get this PHP element working. Thank you in advance for all your help.

 

actually I now have another little problem.

 

I need the form to send via PHPMAIL - I am using the following.

 

<?php

$to = $arr = $_GET['select2']; foreach( $arr as $a){ echo $a;};

$subject = $_REQUEST['Subject'] ;

$message = "This is an online form enquiry sent from the website.

 

Your Name:

".$_REQUEST['parent']."

 

Your Telephone:

".$_REQUEST['telephone']."

 

Your Message:

".$_REQUEST['message']."

 

 

This email was automatically generated. Thank You";

$from = $_REQUEST['email'] ;

$headers = "From: $from";

mail($to,$subject,$message,$headers);

echo "";

?>

 

but i get the following error now:

Warning: mail() expects parameter 1 to be string, array given in /home/marlb/public_html/About/form/submit1.php on line 33

 

Any ideas?

 

This code is find all you need to change is:

 

mail($to, ..

 

to

 

mail(implode(',', $to), ..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.