PHP Classes

MySQL and Radio buttons

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  How to Show Google Ma...  >  All threads  >  MySQL and Radio buttons  >  (Un) Subscribe thread alerts  
Subject:MySQL and Radio buttons
Summary:MySQL and Radio buttons - how to link a db field and radio btn
Messages:5
Author:Brian Read
Date:2007-07-26 10:17:02
Update:2007-08-02 18:54:03
 

  1. MySQL and Radio buttons   Reply   Report abuse  
Picture of Brian Read Brian Read - 2007-07-26 10:17:02
I am having some trouble getting a set of radio buttons to be linked with a db field.

Does anyone have an example of the code, setting "checked" according to the contents of a db field, and then updating the field according to the user edit?

Cheers

Brian

  2. Re: MySQL and Radio buttons   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-07-26 11:27:39 - In reply to message 1 from Brian Read
You may want to take a look at this other class that can be used to integrate the forms class with the database access.

phpclasses.org/databaseaccess

  3. Re: MySQL and Radio buttons   Reply   Report abuse  
Picture of Brian Read Brian Read - 2007-07-26 14:19:52 - In reply to message 2 from Manuel Lemos
I can't see any code in there relevant to radio buttons and db fields.

My problem is that I have some code to set the "checked" parameter to the input tag, which works fine on the first pass, but once the form has been submitted (and when the radio button position has been changed), the code resets it back to what it was, consequently the original value is written back to the db in the "doit" branch. I am sure there must be a trick to it, but I can't quite see what.

Some code using a db field, radio buttons and your forms class which works, would help me no end.

  4. Re: MySQL and Radio buttons   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-08-02 18:09:15 - In reply to message 3 from Brian Read
When you have forms with radio and checkbox fields, you need to pass a flag to the LoadInputValues function to specify whether the form is being presented to the user for the first time or it is being submitted.

  5. Re: MySQL and Radio buttons   Reply   Report abuse  
Picture of Brian Read Brian Read - 2007-08-02 18:54:03 - In reply to message 4 from Manuel Lemos
I am following your example exactly, so I have this:

$form->LoadInputValues($form->WasSubmitted("doit"));

where "doit" is a hidden field.

B.