Check if int is between negative and positive values

Hi,

Why does this not work?
($connection_port_top_angle = -370)

if(($_GET["connection_port_top_angle"] >= -360) && ($_GET["connection_port_top_angle"] <= 360)) {

 - This return true..
 - Only allow numbers between -360 and +360
kgp43Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
HI,

does that work

if($connection_port_top_angle >= -360 && $connection_port_top_angle <= 360)

Regards
0
Brian TaoSenior Business Solutions ConsultantCommented:
You said $connection_port_top_angle = -370, but you're evaluating $_GET["connection_port_top_angle"].
One is a normal variable and the other is an array element.  They are not referring to the same thing.

So why not provide more detail and/or context?
0
Ray PaseurCommented:
Please see: http://iconoun.com/demo/temp_kgp43.php

<?php // demo/temp_kgp43.php
/**
 * See http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28629031.html
 *
 * Limit Integer Values in PHP
 *
 */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);

// Receive the request input, cast it to integer or PHP FALSE
if (!empty($_GET['q']))
{
    if (!is_numeric($_GET['q']))
    {
        echo PHP_EOL . "PLEASE ENTER AN INTEGER";
    }
    else
    {
        $val = !empty($_GET['q']) ? (int)$_GET['q'] : FALSE;

        // If there is non-FALSE, we have usable input!
        if ($val !== FALSE)
        {
            if ($val < -360)
            {
                echo PHP_EOL . "$val IS BELOW THE ALLOWABLE MINIMUM";
            }
            elseif ($val > +360)
            {
                echo PHP_EOL . "$val IS ABOVE THE ALLOWABLE MAXIMUM";
            }
            else
            {
                echo PHP_EOL . "$val IS ACCEPTABLE";
            }
        }
    }
}
// CREATE THE ORM TO RECEIVE INPUT
$form = <<<EOD
<form>
Enter an integer between -360 and +360:
<input name="q" />
<input type="submit" />
</form>
EOD;

echo $form;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kgp43Author Commented:
Perfect, thanks a lot.
0
Ray PaseurCommented:
Thanks for the points - great question!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.