Jump to content

$_POST -> numeric


Ken2k7

Recommended Posts

I want to see if a user's input is numeric.

 

<form action='<?php $_SERVER['PHP_SELF'] ?>' method='post'>
  <input type='text' name='id' size='10' />
</form>

<?php

$id = $_POST['id'];

/* checks if $id is numeric */

?>

 

I tried using is_numeric but that gave me an error. Any help will be appreciated. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/67202-_post-numeric/
Share on other sites

Hi,

 

Check this code...

 

<form action='<?php $_SERVER['PHP_SELF'] ?>' method='post'>
  <input type='text' name='id' size='10' />
  <input type='submit' name='btnClick' value='Click Me' />
</form>
<?php
/* checks if $id is numeric */
if(isset($_POST['btnClick']))
{
if(is_numeric($_POST['id']))
{
	echo "The Entered Value is Numeric";
}
else
{
	echo "The Entered Value is not Numeric";
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/67202-_post-numeric/#findComment-337109
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

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.