Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用文本输入将用户输入的数值传递到数据库中。我希望数据库对大于或等于 0 的所有数值执行插入,但是如果文本框中没有任何内容,我不希望数据库执行插入。所以我想区分0和没有条目。isset 仍然会返回 true。任何帮助都会很棒谢谢
我已经编写了代码,我只需要帮助确定是零还是空的逻辑测试。
您想isset在这种情况下使用,因为它会检测文本框是否为空或未设置,但如果它为 0,它将通过
isset
if (isset($_POST['textbox']))
您可以进一步将它与strlen这样的组合:
strlen
if (isset($_POST['textbox']) && strlen($_POST['textbox']) > 0)