Jump to content

[SOLVED] Posting multiple vars and separating them by semi-colon


jbrill

Recommended Posts

hey guys,

this is probably a very stupid question, but  need some help...

 

i have a list of check boxes in a form, each with a different value ( the value is the id of the colors in the colors table)

as you can see here :

<?
		$colorsquery = mysql_query("SELECT * FROM colors");
		while ($colors = mysql_fetch_array($colorsquery))
		{
		echo '<input type="checkbox" name="color" value="' . $colors['id'] . '"">' . $colors['name'] . '<br />';
		}
		?>

 

my question is, how do i echo the $_POST so that it takes all the checked off boxes and puts values like so: 1;2;3;4;5

 

This stores them in a variable and then echos the color

 

<?php
if($_POST['submit']) {
	$array = $_POST['color'];
	foreach($array as $color) {
		print '<span style="color: ' . $color . ';"> ' . $color . ' </span><br />';
	}
}
else {
	$colorsquery = mysql_query("SELECT * FROM colors");
	print '<form action=' . $_SERVER['PHP_SELF'] . ' method=post>';
	while($colorsarray = mysql_fetch_array($colorsquery)) {
		echo '<input type=checkbox name=color[] value=' . $colorsarray['id'] . ' />' . $colorsarray['name'] . '<br />';
	}
	print '<input name=submit type=submit value=Submit />';
	print '</form>';
}
?>

i tried the explode/implode method with no luck,

 

here is my code:

// combine the colors and seperate with semi colons
		$array = $_POST['color'];
		foreach($array as $color) 
		{

			}

 

is there any other way to do it, or can you show me the proper way? thank you

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.