Search code examples
phpinputshorthand-if

Shorthand if not running or evaluating


I'm basically checking a users download limit in my database, and if their limit is < 1 I want to disable a input on my page.

<input type="text" name="link"<?php ($page["downloads_left"] < 1 ? " disabled=\"1\"" : ""); ?> />

When the page is run, the input is not disabled and I don't have any disabled="1" markup on my page. I have verified that $page["downloads_left"] is less than 1, and it is. It's 0.

Even when I add a string to be outputted if this IF statement evaluates false, it doesn't show in the markup.

Can anyone provide any help? Cheers.


Solution

  • You need to place an echo in the line:

    <input type="text" name="link"<?php echo ($page["downloads_left"] < 1 ? " disabled=\"1\"" : ""); ?> />