Jump to content

[SOLVED] is_int() false condition


ted_chou12

Recommended Posts

Just for future reference, posting "it doesn't work" without explaining in what way it doesn't work doesn't help us help you. Is $guestno an integer value. By that, I mean it is a int, not string, even if the string holds a numeric value.

 

You may want is_numeric? Or you can just use intval to cast it as an integer.

sorry for cutting the details, by it doesnt work, i mean for both "1" and "1a" the result is false.

Thanks

Just to add on, i don't want intval(), i just want to check if the value is interger or not, and i replaced is_int() with is_numeric, it worked, but i have no clue why is_int doesn't work, i strongly believe it's a bug.

string(1) "1", i guess u are right, then what should I use in this situation to test out if the input value is an integer?

<form name="addorder" action="" method="post">
<input name="guestno" value="<?php echo $guestno;?>" type="text" size="30" maxlength="2" /><br />
<?php if (isset($_POST['submit'])){
$guestno = $_POST['guestno'];
if (!is_int($guestno)) 
{echo "<p><b>Guest number field must be in integers!<b></p>"; $invalid = true;}?>

Thanks.

$_POST values are always strings, just so you know.

 

And have you read a thing I said in my first 2 posts. Here's intval

$guestno = intval($_POST['guestno']);

ive read the manual about intval, it does fix the string to make it an integer, but it doesn't check if the input is an integer, that's what i don't like about the function. is there a way to check instead of changing?

Thanks again

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.