php - Checkbox is selected and not assigning a new value -


no matter selected still assigning value of 1 checkboxes , not changing selected checkbox value of 0. here code correct syntax standpoint defaults 1 no matter not see why not changing selected box value '0'

//correct answer variables $chkbox1 = '1'; $chkbox2 = '1'; $chkbox3 = '1'; $chkbox4 = '1'; $chkbox5 = '1';  if (isset($_post['chkbox1'])) {  if ($chkbox1 == 'chkbox1selected') { $chkbox1 = '0'; }  }//end of chkbox1selected logic   if (isset($_post['chkbox2'])) {  if ($chkbox2 == 'chkbox2selected') { $chkbox2 = '0'; }  }//end of chkbox2selected logic   if (isset($_post['chkbox3'])) {  if ($chkbox3 == 'chkbox3selected') { $chkbox3 = '0'; }  }//end of chkbox3selected logic 

your if statements never evaluate true.

take @ 1 checkbox:

$chkbox1 = '1';  if (isset($_post['chkbox1'])) {     if ($chkbox1 == 'chkbox1selected') {         $chkbox1 = '0';     } } 

$chkbox1 set '1', , never changed that, never equal 'chkbox1selected'.

that being said, shouldn't have worry value of checkboxes, since only checked checkboxes sent server.

theoretically, do:

if (isset( $_post['chkbox1'])) {     $chkbox1 = '0'; } 

however, if want read value of checkbox, should able this:

if (isset( $_post['chkbox1'])) {     if ($_post['chkbox1'] == 'chkbox1selected') {         $chkbox1 = '0';     } } 

or, more concisely:

if( isset( $_post['chkbox1']) && ($_post['chkbox1'] == 'chkbox1selected')) {         $chkbox1 = '0'; } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -