Jump to content


Photo

Prefill form data with mysql data.


  • Please log in to reply
2 replies to this topic

#1 tsiedsma

tsiedsma
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 08 March 2006 - 05:41 PM

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.
          <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>

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.

#2 tsiedsma

tsiedsma
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 08 March 2006 - 06:27 PM

OK, I fixed the selection issue. I used the following code and now it selects the appropriate checkbox based on the mysql field value.
          <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>
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?


#3 tsiedsma

tsiedsma
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 08 March 2006 - 06:37 PM

Nevermind, I am a genius and figured it out. I was missing a comma somewhere.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users