tsiedsma Posted March 8, 2006 Share Posted March 8, 2006 I found a piece of code that will check a radio button based on form input but I am pulling data from a database and prefilling the form data so I can update the data stored in the database.[code] <td colspan="2"><input type="radio" name="ud_approved" value="YES" <?php if (isset($_POST['ud_approved']) && $_POST['ud_approved'] == 'YES') { echo 'checked=\"checked\" '; } ?>>YES <input type="radio" name="ud_approved" value="NO" <?php if (isset($_POST['ud_approved']) && $_POST['ud_approved'] == 'NO') { echo 'checked=\"checked\" '; } ?>>NO </td>[/code]I want the radio button to be preselected based on whether or not the field 'approved' in the database says either "YES" or "NO". How can I do this with simple php?The other issue is, I need to update the database with my selection on the radio buttons. If I choose YES or NO, I need it to update to mysql. Do I have to do anything special to make this work? Just so you know, I am able to update every field except the radio buttons. They do not work for updating. Quote Link to comment Share on other sites More sharing options...
tsiedsma Posted March 8, 2006 Author Share Posted March 8, 2006 OK, I fixed the selection issue. I used the following code and now it selects the appropriate checkbox based on the mysql field value.[code] <td colspan="2"><input type="radio" name="ud_approved" value="YES" <?php if ( $approved == 'YES' ) { echo 'checked=\"checked\" '; } ?>>YES <input type="radio" name="ud_approved" value="NO" <?php if ( $approved == 'NO' ) { echo 'checked=\"checked\" '; } ?>>NO </td>[/code]Next issue... If I click on the opposite radio button and click submit to update my changes, it does not update the mysql table. Do I need to tree radio buttons differently for submitting form data to mysql? Quote Link to comment Share on other sites More sharing options...
tsiedsma Posted March 8, 2006 Author Share Posted March 8, 2006 Nevermind, I am a genius and figured it out. I was missing a comma somewhere. Quote Link to comment 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.