checkbox gets checked even when value is empty with empty() function in PHP

williekomodo

New Member
I wrote this code:\[code\] <?php if (!empty($isLocal)) {echo "checked";} ?>\[/code\]Sounds simple? If $isLocal is not empty then check it otherwise don't check it. Yet, it keeps checking it despite the empty value! What's wrong with this?!I had to echo the isLocal a few times across the page and it remains the same - it's still empty yet the checkbox is checked. Yes, I looked at HTML code to see if "checked" is not written and it wasn't. It only prints "checked" inside the PHP logic. the HTML code is this\[code\]Enable this machine:<input type="checkbox" value="http://stackoverflow.com/questions/15580498/1" name="isLocal" <?php if (!empty($isLocal)) {echo "checked";} ?> />\[/code\]
 
Back
Top