1

why this is not working? I want this check the checkbox if pro_cat variable is greater than or equal one else unchecked the checkbox

<?php $checked=""; if($pro_cat>=1){ $checked="checked"; } echo" <tr> <td ><br>Day<hr>Night</td> <td> <label class='container'> <input type='checkbox' checked='$checked'> <span class='checkmark'></span> </label>"; ?> 
3
  • what HTML does this part produce? Did you check what PHP send back to the browser (view source)? I think you will find a hint there. Commented Oct 7, 2019 at 13:42
  • 2
    Replace checked='$checked' with just $checked Commented Oct 7, 2019 at 13:43
  • The fact that you have the word checked at all makes it checked. checked='off' or ='no' or =0 will still be checked. Commented Oct 7, 2019 at 13:49

1 Answer 1

1

Your condition on false becomes like this: <input type='checkbox' checked=''> which is always true for making checked to checkbox. So change like this:

<?php $checked=""; if($pro_cat>=1){ $checked="checked"; } echo" <tr> <td ><br>Day<hr>Night</td> <td> <label class='container'> <input type='checkbox' $checked> <span class='checkmark'></span> </label>"; ?> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.