Jump to content

how to check a checkbox based on database value


vinaip

Recommended Posts

Hi,

 

I have saved a "Y" or "N" in the database field, based on a Checkbox setting in the "Add Contact" screen.

 

Now, in the Edit screen, I want to show the same checkbox, but it should be checked or unchecked, based on the value from the database.

 

How do I check the checkbox based on the edit screen, based on the database value, in PHP? Please help.

 

Thanks,

Vinai

 

I usually code with the more verbose if() statement, and I put PHP inside HTML more than I echo HTML, but there are times for both. Here's another example that does the same thing.

<?
if ($dbval=="Y"){$fieldnamechecked="checked"}
?>

<input type=checkbox name=fieldname <? echo($fieldnamechecked); ?> value=y >

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.