Jump to content

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


aparichit

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?

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']);

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...