Hi,
I have some checkboxes in an html form. This form uses php to email me the users response. So in my html I set the checkboxes up in an array like this:

<label><input type="checkbox" name="weekday[]" value="Monday">M</label>
          <label><input type="checkbox" name="weekday[]" value="Tuesday">Tu</label>
          <label><input type="checkbox" name="weekday[]" value="Wednesday">W</label>
          <label><input type="checkbox" name="weekday[]" value="Thursday">Th</label>
          <label><input type="checkbox" name="weekday[]" value="Friday">F</label>
          <label><input type="checkbox" name="weekday[]" value="Saturday">Sa</label>
          <label><input type="checkbox" name="weekday[]" value="Sunday">Su</label>

... pretty straight forward then in my php I only want the checked ones so I have this code:

foreach($_POST['weekday']  as  $value)  {
		$weekday .= "$value\n";
	}

it works almost perfectly except when I send it to my email, it comes up with the word Array in front of the values like this ArrayMonday Wednesday Friday Sunday .
Does anyone know how to get rid of this? I've searched everywhere and it seems that no one has been able to solve this problem. If anyone can help I would greatly appreciate it.
Thanks!!

Daniel

Recommended Answers

All 5 Replies

Huh! thats strange. Before foreach loop, assign null to $weekday and then try again !

Edit: Or, use another variablename $weekday1. Check this example.

<?php
echo $id;
?>
<html>
<body>
<form method="post" action='test.php'>
<input type=text name=id[]><br>
<input type=submit name=submit value=submit>
</form>
</body>
</html>

Form variables are global by default. (I think).

Huh! thats strange. Before foreach loop, assign null to $weekday and then try again !

How would I make it null? Also if I did that wouldn't it clear out the other values stored in there?

Use a variable with another name.. not $weekday ! :)

GENUIS!! Thanks a lot man. That was such a stupid mistake.

:) You are welcome!

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.