Page 1 of 1

checkbox won't uncheck (value still passed

Posted: Fri Dec 09, 2005 9:31 pm
by yonkman
I am populating a checkbox array from a DB pull. Everyting works fine. The checkboxes that have been previously selected show up correctly.

However, if a user unchecks an item and posts the form, the array still shows that item as checked.

Anyone run into this before?

The code below creates the array. ROW holds the record set where the cols are the array items. ROW2 holds the array names from a lookup table.

Code: Select all

<?

$theCount = 0;
$theTrigger=0;

  while ( $Row2 = mysql_fetch_row( $demoResult2 ) ) 
  {
    if (round($theMidRow) == $theCount)
      {
      $theTrigger = 1;
      }
    if ($theTrigger == 1)
      {
      echo "</td><td>";
      $theTrigger = 2;
      }
  	
    echo "<input type='checkbox' name='amenities[]' value='".$Row2[2]."' ";
  	$theArrayIndex = $Row2[4];
  	if ($Row1[$theArrayIndex] == 1)
      	{
      	echo "checked='checked' ";
  			}
  
  			echo "> ".$Row2[1]."<br />";    
  
    ++$theCount;
  }
?>

Posted: Fri Dec 09, 2005 10:28 pm
by RobertGonzalez
Show your post code. The problem isn't with the selecting of the data it is with the form handling of the data.

post code

Posted: Sat Dec 10, 2005 12:18 am
by yonkman
Thank you!!!!

It was the form handling. The key value was duplicated in the DB I was pulling from. (garbage in, garbage out!!!!). Your response put me on the right debugging path.

Appreciate the insight.

Posted: Sat Dec 10, 2005 8:06 am
by RobertGonzalez
Glad I could be of service.

PostCount++