JackJack Posted April 14, 2006 Share Posted April 14, 2006 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]Examplemysql_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 https://forums.phpfreaks.com/topic/7393-updating-mysql-from-checkboxes/ Share on other sites More sharing options...
craygo Posted April 14, 2006 Share Posted April 14, 2006 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 problemRay Link to comment https://forums.phpfreaks.com/topic/7393-updating-mysql-from-checkboxes/#findComment-26951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.