Skip to content
Advertisement

Update sql record by checkbox in php

I have a problem to update sql record by checkbox in php.My problem is when I press the update button,all can show me update previous info record,but only in the checkbox unable to show me the previous record. Below is my coding:

Checkbox coding:

update function coding:

Below is my output, the red box and the arrow means it unable to show me the previous record to update when I press the update button:

Output

Hope someone can guide me how to solve it. Thanks.

Advertisement

Answer

Checkbox works differently than text field. If you want to show that a checkbox is already selected, then you’ll need to set an attribute “checked” in tag. E.g. Your input checkbox will look something like

P.S:

  1. Since you haven’t mentioned how you are displaying other data, so I am assuming that you are displaying it via the $_POST field, but if you are using some other variable, then you can use that one instead of $_POST
  2. I am assuming that short tags are enabled on server as well, if not, you can replace with . You can read more about short tags in https://www.php.net/manual/en/language.basic-syntax.phpmode.php
  3. Please read about term “Sql Injection”. There are quite a few places where your code is vulnerable to SQL Injection.
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement