I have a problem on how to be able to tick the checkboxes chosen during registration.
If i will update 1 record for example a student, his/her chosen, example his/her interests will be ticked during update.
I have a problem on how to be able to tick the checkboxes chosen during registration.
If i will update 1 record for example a student, his/her chosen, example his/her interests will be ticked during update.
Short answer: when you show the edit form you must read the saved choices for that student and render each checkbox with the checked attribute when the option exists in the saved set. was right to pull status from the database; pointed toward form values on submit; ’s phrasing about “ticking before update” is misleading — the page you render for editing should reflect previously stored choices.
Practical steps (example flow for "interests"):
Example render + process (adapt to your storage choice):
// render
$saved = json_decode($row['interests'], true) ?: [];
foreach ($options as $id => $label) {
$checked = in_array((string)$id, $saved, true) ? ' checked' : '';
echo "<label><input type=\"checkbox\" name=\"interests[]\" value=\"$id\"$checked> $label</label>\n";
}
// process
$selected = (!empty($_POST['interests']) && is_array($_POST['interests'])) ? array_map('intval', $_POST['interests']) : [];
$store = json_encode($selected); // or update join table
// use prepared statement to save $store Troubleshooting: confirm the DB format matches your render logic, ensure checkbox names use [] for arrays, cast types consistently (strings vs ints), and check that your save step clears previously stored choices when none are posted.
Jump to Post— Member #120589What are you talking about when you say "tick the checkboxes during registration".
Nothing is ticked during an update. You tick the checkboxes - THEN you update, e.g. form submission or an ajax event.
you can get the value ticket by $_POST['checkbox'] value..
What are you talking about when you say "tick the checkboxes during registration".
Nothing is ticked during an update. You tick the checkboxes - THEN you update, e.g. form submission or an ajax event.
Get the status of that check box from your DB table.You may be saved that in 0(not checked) or 1 (checked).Check this status when you update the profile. Exg:
<input type="checkbox" name="chkBx" <?php echo ($yourCheckBoxStatus== "0") ? 'checked="checked"' : '' ; ?> value="0" />
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.