Forms Question (Checkboxes)
Moderator: General Moderators
Forms Question (Checkboxes)
As I have my checkbox now.... It is like this.... I left it unchecked.
<input type="checkbox" id="q1" name="q1" VALUE="1">
This posts 1 if the user selects the box, 0 if nothing is selected.
I want to pull from the DB so that if 1 is in the DB the box opens up as checked, how is this possible
<input type="checkbox" id="q1" name="q1" VALUE="1">
This posts 1 if the user selects the box, 0 if nothing is selected.
I want to pull from the DB so that if 1 is in the DB the box opens up as checked, how is this possible
I know this is wrong but it gets you started
Code: Select all
<input type="checkbox" id="q2" name="q2" VALUE="1"
<?php
if ($q2 = 1){
checked;
}
?>little typo. should be ==4Boredom wrote:I know this is wrong but it gets you started
Code: Select all
<input type="checkbox" id="q2" name="q2" VALUE="1" <?php if ($q2 = 1){ checked; } ?>
This should help.... The default variable for checked is below
However i need the following inside that input type to represent checked if q2 = 1... this is where help is needed
The above code is wrong... but thats the best I can do
Code: Select all
<input type="checkbox" id="q2" name="q2" VALUE="1" checked>Code: Select all
<?php
if ($q2 = 1){
checked;
}
?>ok..really no idea what you're trying to do but... for second time4Boredom wrote:This should help.... The default variable for checked is below
However i need the following inside that input type to represent checked if q2 = 1... this is where help is neededCode: Select all
<input type="checkbox" id="q2" name="q2" VALUE="1" checked>
The above code is wrong... but thats the best I can doCode: Select all
<?php if ($q2 = 1){ checked; } ?>
= should be == . as = is not comparison and it will always return true...hence marking all fields as checked..and having invalid html.
Code: Select all
$d = '<input type="checkbox" id="q2" name="q2" VALUE="1"';
if ($q2 == 1){
$d .= ' checked ';
}
$d .= '>';
echo $d;