Member Avatar for nathanpacker

Hey everyone, just need a little help here. First time really getting into PHP, and I'm trying to make a simple form. One part of the form is a set of checkboxes. The name of the field is called "services" and options are thus:
Monitored
Network
License Management
Backup Server
Backup Agent

My html code looks like this:

<form method="post" action="billingadjustment.php"> Services:<br> <input type="checkbox" name="services[]" value="Monitored"> Monitored <br> <input type="checkbox" name="services[]" value="Network" > Network<br> <input type="checkbox" name="services[]" value="License Management" > License Management <br> <input type="checkbox" name="services[]" value="Backup Server"> Backup Server <br> <input type="checkbox" name="services[]" value="Backup Agent"> Backup Agent <br> 

The php code looks like this:

<?php if (isset($_POST['submit'])) { $to = "myemailaddress@domain.com"; $subject = "Billing Adjustment Request"; $requestor = $_POST['requestor']; foreach($_POST['services'] as $servicesbox) { $services .= "Services: $servicesbox\n"; } $body = "From: $requestor\n $services"; mail($to, $subject, $body); header( "Location: http://www.mydomain.com/redirect.html"); } else { echo "blarg!"; } ?> 

I was just using some code I got out of a book, and it seems to work but just a couple problems. It gets sent to my email address, and the ouput for the checkboxes looks like this:

ArrayServices: Monitored Services: Network Services: License Management 

Question 1: How do I get it to not put the word "array" in front of the first option.

Question 2: I would like it to just output the word "Services" once, then maybe put all the options that were chosen after it, maybe separated with commas or something. I know that probably has to do with the "foreach" command I'm using, but I don't know how to fix it.

So I guess I want it to come out looking something like this:

Services: Monitored, Network, License Management 

Any help?
Thanks in advance!

EDIT: Nevermind guys! I should have just thought about it a bit before I asked you all. I changed this bit of code:

<?php $to = "myemailaddress@domain.com"; $subject = "Billing Adjustment Request"; $requestor = $_POST['requestor']; foreach($_POST['services'] as $servicesbox) { $services .= "Services: $servicesbox\n"; }?> 

I added a variable called services, and did this:

$to = "natepacker@gmail.com"; $subject = "Billing Adjustment Request"; $requestor = $_POST['requestor']; $services = "Services: "; foreach($_POST['services'] as $servicesbox) { $services .= "$servicesbox, "; }?> 

Works just the way I want it to now! Only, I still don't get why it was putting the word "Array" in front of it before.
Thanks!

Member Avatar for Puckdropper

Congratulations on solving your own problem.

$services in your foreach section was initially an array. When you used it in $services .= "Services: $servicesbox\n"; PHP just said "Hm... That's an array." and appended the word Array to the string. (It does that for debug purposes. You don't want screenfuls of data to be echoed when you are trying to figure out if the variable's working right.)

Member Avatar for nathanpacker

Ah, I got it. Thanks.

Member Avatar for Puckdropper

You're welcome. (It's an experience thing... I've asked the same questions.)

Member Avatar for nathanpacker

You're welcome. (It's an experience thing... I've asked the same questions.)

Man, you are quick.:)

Member Avatar for Puckdropper

We just happened to be on at the same time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.