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

 

Link to comment
Share on other sites

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>';
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.