Page 1 of 1

updating a checkbox [Solved]

Posted: Wed Feb 16, 2005 7:37 pm
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

Posted: Wed Feb 16, 2005 8:31 pm
by feyd
yes.

Posted: Wed Feb 16, 2005 9:27 pm
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; 

?>" />

Posted: Wed Feb 16, 2005 9:34 pm
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' : ''?>>

Posted: Wed Feb 16, 2005 9:36 pm
by feyd
the attribute name of 'checked' makes it always checked. Make it echo 'checked="checked"'