Jump to content

Can't pass any numeric digit via GET/POST method


Recommended Posts

Just let a code snippet,for example like this:

<?phpvar_dump($_GET['num']);?><form method="get" action="<?=$_SERVER['PHP_SELF'] ?>">Insert numeric digit: <input type="text" name="num" /><br /><input type="submit" value="Submit Digit!" /></form>

Now though I pass any numeric digit[say 5] through that form, it becomes a string in output [like: string(1) "5"].Can anyone tell me, Why this problem occurs & How do I turn that in numeric again?

  • Like 1
Link to comment
Share on other sites

All input data is considered a string because there is nothing in the HTTP protocol indicating what data type the query string parameters are. You can cast it to an integer using the intval() function.

$_GET['num'] = intval($_GET['num']);

  • Like 2
Link to comment
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...