vinpkl Posted April 5, 2011 Share Posted April 5, 2011 hi all I have 3 checkboxes whose values are getting stored in the database with a comma separator. <input name="color[]" type="checkbox" value="red" id="red" />red <input name="color[]" type="checkbox" value="blue" id="blue" />blue <input name="color[]" type="checkbox" value="green" id="green" />green values getting stored with comma separator red, blue, green now i want to show the checkboxes as "checked" to show the customer as which colors they chose lasttime when they submitted the form. How can i make it possible ? If it is possible without the comma separator then i can remove the comma. vineet Quote Link to comment https://forums.phpfreaks.com/topic/232752-checkbox-checked-with-database-value/ Share on other sites More sharing options...
Lyleyboy Posted April 8, 2011 Share Posted April 8, 2011 Ideally you would store each form field separately. The code you are looking for is something like Inside your record set while if($row['red'] == 1){ echo "<input type="chcekbox" checked"/>"; } else { echo "<input type="chcekbox""/>"; } So if the field is set in the recordset the checkbox will display correctly. Tadaa Quote Link to comment https://forums.phpfreaks.com/topic/232752-checkbox-checked-with-database-value/#findComment-1198731 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.