Jump to content

Updating Mysql From CheckBoxes


JackJack

Recommended Posts

I want it so that the boxes which are ticked will change a cell in there row to 'Yes'.

Here is my code so far but i don't think i'm doing it right

[code]
if($action == changebankallow){

echo "<br><br>Select Members:<br>";

echo "<form method='post' action=clan.php?action=allowmembers>";

            $members1 = mysql_query("select * from `players` where `clan_name` = '$clan[name]'order by `display_name` asc");
                while($member = mysql_fetch_array($members1)) {


if ($member[clan_bank] == Yes){
  $checked="checked";
}else{
  $checked="";
}

echo "<input type='checkbox' name='MEMBER_ARRAY[]' value='$member[id]' $checked> $member[display_name] ($member[clan_bank])<br>";
}
echo "<input type=submit value=Update>";

echo "</form>";

if($action == allowmembers){
if ($MEMBER_ARRAY)
{
$MEMBER = implode($MEMBER_ARRAY, ",");
$result = mysql_query ("UPDATE players SET clan_bank =Yes where id='$MEMBER'");
echo "Updated Successful";
if(!$result)
{
echo "<B>UPDATE unsuccessful:</b> ", mysql_error();
exit;
}
}
[/code]

Example
mysql_query ("UPDATE players SET clan_bank =Yes where id='box(es) that was ticked'");

So i'd want more than one update if you get what i meen.


JJ

Link to comment
Share on other sites

you are trying to create your array before the page is submitted. You have to submit the page then get the values into an array then run your query. This is how I have always done it.

[code]if($action == changebankallow){
echo "<br><br>Select Members:<br>";
echo "<form method='post' action=clan.php?action=allowmembers>";
// Start count for values
$i = 1;
            $members1 = mysql_query("select * from `players` where `clan_name` = '$clan[name]'order by `display_name` asc");
                while($member = mysql_fetch_array($members1)) {
if ($member[clan_bank] == Yes){
  $checked="checked";
}else{
  $checked="";
}

echo "<input type='checkbox' name='mem".$i."' value='$member[id]' $checked> $member[display_name] ($member[clan_bank])<br>";
$i++;
}
echo "<input type=submit value=Update>";

echo "</form>";

if($action == allowmembers){
$access = '';
$MEMBER = array();
$initials = 'mem';
foreach ($_POST as $key => $value) {
  $access .= "$key=$value&";
  if (substr($key, 0, 3) == $initials) {
    $MEMBER[]= ''.$value.'';
}
}
$result = mysql_query ("UPDATE players SET clan_bank =Yes where id IN ($MEMBER);
echo "Updated Successful";
if(!$result)
{
echo "<B>UPDATE unsuccessful:</b> ", mysql_error();
exit;
}
}[/code]

I have not tested all of your code so let me know if there is a problem

Ray
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.