I have written a custom plugin for people to sign up to a course. The data is submitted in a front end form and stored in a custom table in the database. There is a "course_completed" column that is a boolean that by default is set to 0 (not checked/false).
Then I have a table that gets the data from the database of the people who have registered to the course. Once the course is over the admin should be able to check who has completed the course and click save. I am struggling to find a way that once the checkbox is ticked for a person, their "completed_course" value is changed to 1 in the database.
Code to display database data in table on the backend:
<tbody class="alternate">
<?php
global $wpdb;
$table_name = $wpdb->prefix . 'crm';
$result = $wpdb->get_results ("SELECT * FROM $table_name");
?>
<?php foreach ($result as $field): ?>
<tr>
<td><?php esc_attr_e( $field->id, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->time, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->first_name, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->last_name, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->email, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->phone, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->postcode, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->city, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->address, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->course, 'wp_admin_style')?></td>
<td><input type="checkbox" name="course_completed" value="1" <?php checked( $field->course_completed, 1 ); ?> /></td>
</tr>
<?php endforeach; ?>
</tbody>
Not sure if I am supposed to be using AJAX, a form inside the table or something else.