Member Avatar for Zagga

Hi folks,

I have a mysql database and I have written some PHP to view records, add records, delete records and update records. The problem I have is updating checkbox fields of a record. Everyhting was working fine and updating correctly.
Then I tried to automatically populate the form fields with data held in the database. I can get everything populated correctly and the text boxes update correctly but the checkboxes always return the original value and ignores any changes made to them.

The code I am using to populate the form fields is ...

echo "<input type='checkbox' name='DayRemind' value='$row[DayRemind]' />&nbsp;Day Reminder<br />";

Does anyone know of a way I can populate the checkboxes with whatever value is in the database but also allow changes to be made to them?

Zagga

You've to try something like this:

if ($row['DayRemind'] == '1')
{
  $sel = "Selected";
}
echo "<input type='checkbox' name='DayRemind' value='1' $sel />&nbsp;Day Reminder<br />";
Member Avatar for Zagga

You've to try something like this:

if ($row['DayRemind'] == '1')
{
  $sel = "Selected";
}
echo "<input type='checkbox' name='DayRemind' value='1' $sel />&nbsp;Day Reminder<br />";

Thank you kishan112,

I'm not sure how I missed that, just needed a fresh pair of eyes on it I guess :)

I changed the code very slightly but your idea worked how I need.

if ($row['DayRemind'] == '1')
{
$che = "checked='checked'";
}
echo "<input type='checkbox' name='DayRemind' value='1' $che />&nbsp;Day Reminder<br />";
$che = "";

Thanks again.
Zagga

Hi folks,

I have a mysql database and I have written some PHP to view records, add records, delete records and update records.

Hi Zagga

I believe I have pretty much the same issue. Would you mind having a quick look at my post here and if you don't mind, share your idea with me?

Hope you don't mind, Thank you

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.