Jump to content
xisto Community
ginginca

Checking To See If Something Is Not An Integer

Recommended Posts

I put together this:

//Make Sure $qty is NOT blank before checking if it is a number	if (!empty($item_1_qty)) {//not empty			}	if (intval($item_1_qty) !== $item_1_qty){			//item 1 qty is not a whole number			$redirect_to = 'order_form.php?error=6';				header("Location: $redirect_to");			exit();		}

But I get my error message coming no matter whether it is an integer or not.
Edited by ginginca (see edit history)

Share this post


Link to post
Share on other sites

I put together this:

//Make Sure $qty is NOT blank before checking if it is a number	if (!empty($item_1_qty)) {//not empty			}	if (intval($item_1_qty) !== $item_1_qty){			//item 1 qty is not a whole number			$redirect_to = 'order_form.php?error=6';				header("Location: $redirect_to");			exit();		}

But I get my error message coming no matter whether it is an integer or not.
If your variable is coming from a form i reccomend you to cast it before you use it, its simple:
$item_1_qty = (int) $_POST['item_1_qty'];
Also take a look to the is_numeric() php function, because it is recommended to use it with variables that are submited by a form.

Best regards,

Share this post


Link to post
Share on other sites

..and why not better to use a function is_numeric() to see if the variable is a number or a numeric string, or you really need it to be integer.. But if so, the above replies have said enough. :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.