Jump to content

using multiple select box to update database


Sabmin

Recommended Posts

This has been bugging me for quite a while and I've tried so many different things and just run into all kinds of problems...

 

What I'm doing or trying at least is pulling data from a table displaying it into a multiple select box allowing the user the oppertunity to remove one or more options.  As the code stands now I'm getting no value at all in the post variable, by taking the [] brackets out of the inputs name i was able to get the first selected option but the php code was then unable to remove that value from the database.  I hope I'm explaining this well enough but the code follows I'd really appreciate some help or direction on this one.

 

The FORM

                <FORM action='' method='post'>
                    <select size='8' multiple name='remove_player[]'>
<?php
foreach ($members as $key => $mem) {
    if ($mem != "") {
        $mem = str_replace("-", " ", $mem);
        $mem = ucwords($mem);
        echo ("<option value='" . $mem . "'>" . $mem . "</option>");
    }
}
?>
                    </select>

 

 

and then the handler code:

        $to_remove = $_POST['remove_player'];
	$as_team = str_replace(" ", "-", $teamname);
	$as_team = strtolower($as_team);
	$for_remove = "SELECT * FROM teams WHERE name = '$as_team'";
	$for_query = (mysql_query($for_remove));
	foreach ($to_remove as $y => $z) {
		$z = str_replace(" ", "-", $z);
		$z = strtolower($z);
	}
	while($arr_remove = mysql_fetch_array($for_query)) {
		foreach ($arr_remove as $a => $b) {
			foreach ($to_remove as $c => $d) {
				if ($b == $d) {
					unset($arr_remove[$a]);
				}
			}
		}
		foreach ($arr_remove as $e => $f) {
			$add_replace = (mysql_result($for_query, 0, 'members'));
			$replace = ($add_replace . "\r\n" . $f . "\r\n");
			$replace_mem = "UPDATE teams SET members = '$replace'";
			$replace_q = (mysql_query($replace_mem));
		}
	}
	echo "Member List successfully updated.<br>";
	foreach ($to_remove as $h => $g) {
		echo ($g . " removed from the team.<br>");
	}

 

Also any time i try to print any part of the array/s I get no values but the database is being updated with 2 line breaks and a "3" at the end of the table which has me a bit confused as well.

 

Thanks!

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.