updating a checkbox [Solved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

updating a checkbox [Solved]

Post by C_Calav »

hi guys,

i have a check box on my insert page which works fine.

but on my update page, how do i pull wheather it is checked or not out of the DB?

do you do write some code that checks if checkbox feild "yes" or "empty" then decided if checkbox is "checked" or not in html?

is that the correct way or is there a better way?

thanx
Last edited by C_Calav on Wed Feb 16, 2005 11:05 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes.
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

thanx feyd.

this works as in it updates correctly if the user checks it or not, but when the results are pulled out of the DB it always shows that the checkbox is checked, when sometimes in fact it isnt.

do i have something wrong here?

Code: Select all

<input type="checkbox" name="ud_P_Active" value="yes" checked="

<?php 

if (!empty($P_Active)) 
&#123; 
echo "checked"; 
&#125; 

?>" />
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hey

Maybe try something like this

Code: Select all

<input type="radio" name="ud_P_Active" class="input-box" value="yes"<?php echo $_POST&#1111;'ud_P_Active']=='yes' ? 'checked' : ''?>>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the attribute name of 'checked' makes it always checked. Make it echo 'checked="checked"'
Post Reply