-3

这看起来很简单,但我不知道为什么它不起作用。

我需要写一个 if 语句

 first, checks if it is numeric  

 second, if it is not between 1 and 10, issue errorA

 third, if it is not between 20 and 30, issue errorB

 fourth, it is not a number, issue errorC

如果不是数字且满足所有范围,则添加到数据库中。

无论如何,我不确定 if 和 while 组合可以满足这一点....

到目前为止,我有,

如果数字并满足范围,则添加到数据库,否则发出错误C

如何过滤错误 A 和 B?

if ( isset [some code...]) {

    $a = ...;
    $b = ...);
    $c = ...;

    if (preg_match('/^\d+$/',$b) && preg_match('/^\d+$/',$c) &&
        ((1 <= $b && 10 >= $b)) && ((20 <= $c && 30 >= $c))) {

        $sql = "INSERT [some code...]

        mysql_query($sql);

        $_SESSION['success'] = $_POST['success'];
        header('Location: index.php') ;
        return;

    } else {

        $_SESSION['error'] = $_POST['error'];
        header('Location: index.php') ;
        return;
    }

}
4

1 回答 1

0
if (preg_match('/^\d+$/',$b) && preg_match('/^\d+$/',$c)) {
    if (($b >= 1 && $b <= 10) && ($c >= 20 && $c <= 30)) {
        echo "OK";
    } else {
        echo "not in range";
    }
} else {
  echo "not a number";
}
于 2013-02-25T20:49:03.037 回答