# Unwanted ERROR message on form

**URL:** <https://forum.kirupa.com/t/unwanted-error-message-on-form/265068>\
**Category:** programming\
**Created:** [July 3, 2008, 3:41pm UTC](https://forum.kirupa.com/t/unwanted-error-message-on-form/265068 "2008-07-03T15:41:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![agabrel](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@agabrel](https://forum.kirupa.com/u/agabrel)\
**Post date:** [July 3, 2008, 3:41pm UTC](https://forum.kirupa.com/t/unwanted-error-message-on-form/265068/1 "2008-07-03T15:41:11Z")

</div>

In my form I have three groups of checkboxes. When someone selects no box in one group it gives back and echo error message:  
[COLOR=“Red”][SIZE=“2”] Warning: Invalid argument supplied for foreach() in /home/jimmyweb/public\_html/mailer.php on line 15

Warning: Invalid argument supplied for foreach() in /home/jimmyweb/public\_html/mailer.php on line 18

Warning: Invalid argument supplied for foreach() in /home/jimmyweb/public\_html/mailer.php on line 21

Warning: Invalid argument supplied for foreach() in /home/jimmyweb/public\_html/mailer.php on line 24

Warning: Invalid argument supplied for foreach() in /home/jimmyweb/public\_html/mailer.php on line 27[/COLOR][/SIZE]

here is my php:

```php
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>

```

how can I change it so it won’t give the message? do I change the {else}  
echo or is there something I’m missing around my foreach?

my foreach

```php
foreach($_POST['services'] as $value) {
$services_msg .="Services Desired: $value
";
}

```

Please help.

---

<div class="post-metadata">

**Author:** ![Charleh](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@Charleh](https://forum.kirupa.com/u/Charleh)\
**Post date:** [July 3, 2008, 3:47pm UTC](https://forum.kirupa.com/t/unwanted-error-message-on-form/265068/2 "2008-07-03T15:47:31Z")

</div>

The $\_POST data must contain an array to use a foreach on it

You need to check if it’s blank using isset($\_POST[‘Services’]) before looping

Additionally - is this all the code? The stuff you posted?

You can’t use an else like that if so 😛

---

<div class="post-metadata">

**Author:** ![agabrel](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@agabrel](https://forum.kirupa.com/u/agabrel)\
**Post date:** [July 3, 2008, 4:00pm UTC](https://forum.kirupa.com/t/unwanted-error-message-on-form/265068/3 "2008-07-03T16:00:43Z")

</div>

no, here is my full code. it is working except the messegaes =(

```php
<?php 
if(isset($_POST['submit'])) {
$to = "gabi@vertexmarketing.com";
$subject = "Talent/Materials Request Form";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$title_field = $_POST['title'];
$organization_field = $_POST['organization'];
$address_field = $_POST['address'];
$city_field = $_POST['city'];
$state_field = $_POST['state'];
$zip_field = $_POST['zip'];
$phone_field = $_POST['phone'];
$cell_field = $_POST['cell'];
foreach($_POST['services'] as $value) {
$services_msg .="Services Desired: $value
";
}
foreach($_POST['talent'] as $value) {
$talent_msg .="Talent Desired: $value
";
}
foreach($_POST['artists'] as $value) {
$artists_msg .="Artists Desired: $value
";
}
foreach($_POST['reels'] as $value) {
$reels_msg .="Reels Desired: $value
";
}
foreach($_POST['videos'] as $value) {
$videos_msg .="Videos Desired: $value
";
}
$date_field = $_POST['date'];
$time_field = $_POST['time'];
$ecity_field = $_POST['ecity'];
$estate_field = $_POST['estate'];
$country_field = $_POST['country'];
$people_field = $_POST['people'];
$budget_field = $_POST['budget'];
$message = $_POST['message'];
$body ="Name: $name_field
 Title/Position: $title_field
 Organization: $organization_field
 
 Address: $address_field
 City: $city_field
 State: $state_field
 Zip: $zip_field
 
 Phone: $phone_field
 Cell: $cell_field

 E-Mail: $email_field

 $services_msg 
 $talent_msg
 $artists_msg
 $reels_msg
 $videos_msg
 Event Date: $date_field
 Time: $time_field
 
 City: $ecity_field
 State: $estate_field
 Country: $country_field
 
 # of People Attending: $people_field
 
 Approximate Budget: $budget_field

 Question/Comments:
 $message";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>

```

---

<div class="post-metadata">

**Author:** ![djheru](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/djheru/32/3190_2.png) [@djheru](https://forum.kirupa.com/u/djheru)\
**Post date:** [July 3, 2008, 5:06pm UTC](https://forum.kirupa.com/t/unwanted-error-message-on-form/265068/4 "2008-07-03T17:06:28Z")

</div>

If no checkboxes are checked, the $\_POST[‘services’] array key will not be created. Just add a check to see if it exists first.

---

<div class="post-metadata">

**Author:** ![agabrel](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@agabrel](https://forum.kirupa.com/u/agabrel)\
**Post date:** [July 3, 2008, 6:03pm UTC](https://forum.kirupa.com/t/unwanted-error-message-on-form/265068/5 "2008-07-03T18:03:40Z")

</div>

Yes. but I don’t want the error message if none of the boxes selected.

---

<div class="post-metadata">

**Author:** ![jwilliam](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jwilliam](https://forum.kirupa.com/u/jwilliam)\
**Post date:** [July 3, 2008, 6:18pm UTC](https://forum.kirupa.com/t/unwanted-error-message-on-form/265068/6 "2008-07-03T18:18:24Z")

</div>

Put this at the beginning of your script:

```auto

error_reporting(0);

```

I prefer to turn off error reporting in my php.ini file. Google php.ini and you’ll find all kinds of stuff I’m sure…

---

<div class="post-metadata">

**Author:** ![agabrel](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@agabrel](https://forum.kirupa.com/u/agabrel)\
**Post date:** [July 3, 2008, 9:19pm UTC](https://forum.kirupa.com/t/unwanted-error-message-on-form/265068/7 "2008-07-03T21:19:44Z")

</div>

It works !! =)  
Thank you.

---

<div class="post-metadata">

**Author:** ![Charleh](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@Charleh](https://forum.kirupa.com/u/Charleh)\
**Post date:** [July 4, 2008, 8:52am UTC](https://forum.kirupa.com/t/unwanted-error-message-on-form/265068/8 "2008-07-04T08:52:55Z")

</div>

Turning off error reporting is just hiding a problem - the problem is that your code isn’t 100% right and you are just hiding the warning messages. Granted, the messages are just warnings and the code doesn’t cause any real problems but it’s the principal that counts - you don’t learn proper syntax or coding methods by dodging the errors
