Good evening, all!

I'm trying to display multiple checkbox values in a summary screen of sorts. The website is about movies, and if somebody checks that they like more than one movie type, I would like all of their choices shown. I currently get "Your favorite movie type is: Array" as a response.

Can somebody please point me to my error?

Thank you so much.

- Jim

if(isset($_POST['type'])){
		$type = $_POST['type'];	
		$received[] = "Your favorite movie type is: $type";
		foreach($type as $var){ 
			echo $var;}
		
	}

Recommended Answers

All 3 Replies

how is your form setup?

generally you would want a series of checkbox fields all called type[] with unique values.

this way what you go to parse over the results in php, $_POST is an array of check values.

if(isset($_POST['type'])){
		$type = $_POST['type'];	
		echo 'You selected: ' . implode( ',', $type);

		// You selected: horror, sci-fi, romance
	}

Here is the example of how the form is set up:

Action <input type="checkbox" name="type[]" value="Action" 
			<?php if (!empty($type)&&in_array('Action', $type)) echo 'checked="checked"'; ?>
			/>

then you should just be able to parse over $_POST as an array.

the implode example i provided will just display all the type values as a comma delimited string.

if you want to parse over the array use something like

foreach( $_POST['type'] as $sType )
{
   echo $sType . '<br />';
}
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.