0

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

3
Contributors
3
Replies
6
Views
7 Years
Discussion Span
Last Post by zeroge
1

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 />";
0

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

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.