简体   繁体   English

PHP如果Post Value小于或大于

[英]PHP If Post Value is less than or greater than

I have a php booking form which checks to make sure that information has been entered in the boxes before its submitted: 我有一个php预订表格,该表格进行检查以确保在提交信息之前已在框中输入信息:

I use the following to check to make sure group has a value in it. 我使用以下内容检查以确保组中具有值。

if(!isset($_POST['group']) || trim($_POST['group']) == '')
{
    $error.= "Group Size is required<br/>";
}

How can I use an IF statement too check that the value in group is greater than 39 but less than 400? 如何使用IF语句检查组中的值是否大于39但小于400?

if(!empty($_POST['group']) && is_numeric($_POST['group']))
{
    if($_POST['group'] < 400 && $_POST['group'] > 39)
    {
        //here you go
    }
}

The empty also checks for existence. 空也检查是否存在。 You should always check the type of the values youre getting, not only if empty - type casting gets done by php for you 您应该始终检查获取的值的类型,不仅要检查是否为空-类型转换由php为您完成

Other answer is wrong btw, question is greater than 39, not greater or equal 39 顺便说一句,其他答案是错误的,问题大于39,不大于等于39

做就是了

if(strlen(trim($_POST['code'])) >= 39 && strlen(trim($_POST['code'])) < 400)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM