Hi all, hoping someone can helkp me here.. At the moment for text boxes i use this to populate the form field from my database, where $a1[lname] is pulled from the DB <tr> <td><label for="lname">Last Name</label></td> <td><input type=text name=lname size=23 value="<?=$a1[lname]?>" id="lname"></td> </tr> Code (markup): I need to do the same thing for a radio button ie store which option has already been selected by the user. This is the code i have for the radio button itsself but im not sure how to make one selected - based on whats stored in the db <tr> <td> <input type="radio" name="email_signup" id="yes" value="yes" checked> <label for="yes">Yes please</label> <input type="radio" name="email_signup" id="no" value="no"> <label for="no">No thanks</label> </td> </tr> Code (markup): the value of the checkbox is stored as either a 1 or a 0 depending on yes or no.. any ideas how i could insert this? im using php and mysql Thanks Mike
<?php if $a1[check] == 1 { echo 'checked'; }?> PHP: At both options. I thought radio is done with 'on' instead of checked. Might want to double-check that. But that's how you cuold transfer the value from DB to HTML.
thanks Tops30 I double checked the code online and everywhere i look seems to suggest using checked rather than on. The code worked a treat, with the addition of brackets - thanks again Mike
Yeah doh... Silly me. if(whatever)... Glad it's working for you. I always forget simple HTML stuff like checkboxes and radio button functionality. Oh well, with Google you can find those answers in seconds so why know if off the top of your head?!
thats a good point - except when people ask for help and all people answer is "Google it goddamit"! - lol - i think that is it gone too far!
Yes, I didn't mean the Google thing for that PHP question since it's custom code you won't easily find an answer to. However, all HTML questions can easily be Googled IMO. Sometimes it takes longer to post the question in a forum than to find the answer in Google.