submit ID using multiple checkboxes in PHP HTML Mysql -


i using multiple html checkboxes submit student attendance. checkbox once clicked submit '1' , if not checked, submit '0'. able submit '1' when checked cant submit '0'. below code:

<?php     $subcheck = (isset($_post['subcheck'])) ? 1 : 0;     $date = date("y/m/d");     foreach ( $student $attendance ) {               echo "<tr>";               echo "<td>$attendance->id</td>";                 echo "<td>$attendance->name</td>";                 echo "<td>                         $attendance->classroom_id                       </td>";?>                     <input type="hidden" name="date[]" value="<?php echo $date;?>" />              <td><input type="checkbox" name="status[]" value="<?php echo $attendance->id;?>"></td>              <td><input type="text" name="reason[]" ></td>        <?php             }             ?> <tr>         <td colspan="2" align="center"><input type="submit" value="save" name="submit"></td> 

this might give ideas:

<?php     $subcheck = (isset($_post['subcheck'])) ? 1 : 0;     $date = date("y/m/d");      $out = '<table id="tblattendance"><thead><th>id</th><th>name</th><th>room</th><th>status</th><th>reason</th></thead><tbody>';     foreach ( $student $attendance ) {         $out .= '<tr>';         $out .=     '<td>' .$attendance->id. '<input type="hidden" name="studentid[]" value="' .$attendance->id. '"></td>';         $out .=     '<td>' .$attendance->name. '<input type="hidden" name="name[]" value="' .$attendance->name. '"></td>';         $out .=     '<td>' .$attendance->classroom_id. '<input type="hidden" name="classroomid[]" value="' .$attendance->classroom_id. '"></td>';         $out .=     '<td><input type="checkbox" name="status[]" value="yes"></td>';         $out .=     '<td><input type="text" name="reason[]" ></td>';         $out .= '</tr>';     }     $out .= '<tr><td colspan="2" align="center"><input type="submit" value="save" name="submit"></td></tr>';     $out .= '</tbody></table>';     $out .= '<input type="hidden" name="date" value="' .$date. '" />';     echo $out; ?> 

since using type="submit" button, presume have inside form construct?

recall how checkboxes work in html forms: if box checked, value received on php side value="yes" value. in other words, variable $_post['status'][n] have value yes.

however, if checkbox not set, $_post['status'][n] not set.

reference:

http://www.html-form-guide.com/php-form/php-form-checkbox.html


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -