HEY
i am trying to learn php and i tried making a small script that tells the user to type in a number...and checks if its an integer..if its not an integer it gives an error..but its not working...no matter wt they enter..it says that its not an integer
here is the code
PHP Code:
Please enter some numbers..ONLY NUMBERS<br>
<form action="<?$_SERVER[PHP_SELF]?>" method='post'><br>
<input type='text' name='input'> <br>
<input type='Submit' name='Submit' value='Submit'>
</form>
<?
$stuff=$_POST['input'];
$submit= $_POST['Submit'];
$get = gettype($stuff);
$get=gettype($stuff);
if (isset($submit)){
if ($get != 'integer') {
echo "You posted $stuff and its not an integer";}
else
{echo "thanks " ;}
}
else
{}
hey i am sorry i dont know what that is
i am new to php and the first tutorial i read was on gettype() and settype() so i tried messin with it but it dint work...duno wts wrong wid it?
grr
is anyone going to tell me whats wrong wid the script?
i know php.net is a great site!!!
i bought a BOOK and i am reading it
the first chapter talked about this thing and i tried to play with it to learn and its not working as it should and i am asking someone to tell me HOW 2 FIX IT! not to tell me to go to that site to learn this or that !!
Please enter some numbers..ONLY NUMBERS<br>
<form action="<?$_SERVER[PHP_SELF]?>" method='post'><br>
<input type='text' name='input'> <br>
<input type='Submit' name='Submit' value='Submit'>
</form>
<?
$stuff=$_POST['input'];
$submit= $_POST['Submit'];
$input=$_POST[input];
if (isset($submit)){
if (is_int($input)) {
echo "You posted $stuff and its not an integer";}
else
{echo "thanks " ;}
}
else
{}
because i am trying to learn php so i need to know y its not working..i am not trying to create a script just learning
and the other one dint work either
learn.apkafuture.com/ops.php
and using is_int will produce the same result. Btw, to quote the PHP manual:
However, you could use (int)$_POST['input'] , or intval($_POST['input']). That would solve your problem...almost. If anything other than numbers are posted..intval or (int) will return 0, which will still pass as an integer.
A good way to do it would probably be to do a preg_match
PHP Code:
<?php
$stuff = '9';
if(!preg_match('/([0-9]+)/', $stuff))
{
echo "You posted $stuff and its not an integer";
}
else
{
echo "thanks ";
}