Reputation: 6799
I have two fields in my database and they are- name and user_id. I have a page called name.php where I have fives names and checkboxes for each of those names. Now what I want to do is when I visit the page “name.php”, I want names checked which are already inserted in the database. Would you please kindly help me to do this? Thanks in Advance
Upvotes: 0
Views: 182
Reputation: 174977
Go over the records of the database, and when generating the chekboxes, see if the name appears in the database. If it does, add checked="checked"
to the checkbox.
Upvotes: 0
Reputation: 43820
if the value in the db says it is checked you can add the checked attribute to the input element
<input type="checkbox" name="thename" checked="checked" />
so in your code it will be like:
<input type="checkbox" name="thename" <?php echo $value == 1 ? 'checked="checked"' : ''?> />
this will add the checked attribute if the value is equal to 1
Upvotes: 4