-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 に答える