How can I check if form input is numeric in PHP?

I need to be able to see if a form input in PHP is numeric. If it is not numeric, the website should redirect. I have tried is_numeric() but it does not seem to work.

Code examples will be nice.

I am developing a shopping cart that accepts an integer value for the quantity. I am trying this:

                echo "is not numeric";


if(!is_numeric($quantity == 0)){
                echo "is not numeric";

What you have here are two nested conditions. Let's say $quantity is 1.

The first condition evaluates 1 == 0 and returns FALSE. The second condition checks if FALSE is numeric and returns FALSE because FALSE is not numeric.

just write:

if (!is_numeric($quantity))
    echo 'is not numeric';

Need Your Help

How to start an another activity in android after webview has been loaded?

android webview

Using Webview am loading web url in android.Basically in webview am loading Login Page web url .That page allow user to login with using openid like Facebook and Google.

How to splitAt a scala list using shapeless

scala shapeless

I'm trying to split a list of size S at N, where it is known that N, M sum up to S. This does not compile: