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.

Dani AI

Generated

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"):

  1. Store selections in a predictable format (JSON array, CSV, or — preferably — a normalized join table).
  2. When building the edit form, decode the saved value into an array and loop your available options. Mark a checkbox as checked when that option is in the saved array.
  3. When processing the posted form, remember unchecked boxes do not appear in POST; treat the absence as an empty array and update the DB accordingly. Validate and sanitize posted values and use prepared statements.

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.

Recommended Answers

All 3 Replies

you can get the value ticket by $_POST['checkbox'] value..

Member Avatar for Member #120589

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" />
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.