[advanced search]
Results from the most recent live auction are here.
20 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Domain Name Industry Newsletter
Go Back   NamePros.Com > Design and Development > Programming
User Name
Password

Old 04-07-2006, 03:46 PM   · #1
unknowngiver
Senior Member
 
Name: Zubair
Location: Ontario Canada
Trader Rating: (53)
Join Date: May 2005
Posts: 2,754
NP$: 724.15 (Donate)
unknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to all
wts wrong here

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
{}


?>


Please register or log-in into NamePros to hide ads
unknowngiver is offline   Reply With Quote
Old 04-07-2006, 03:50 PM   · #2
clowesy
Account Suspended
 
Trader Rating: (13)
Join Date: Aug 2005
Posts: 379
NP$: 385.00 (Donate)
clowesy is a jewel in the roughclowesy is a jewel in the roughclowesy is a jewel in the rough
use the is_int() function.
clowesy is offline   Reply With Quote
Old 04-07-2006, 04:06 PM   · #3
unknowngiver
Senior Member
 
Name: Zubair
Location: Ontario Canada
Trader Rating: (53)
Join Date: May 2005
Posts: 2,754
NP$: 724.15 (Donate)
unknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to all
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?
unknowngiver is offline   Reply With Quote
Old 04-07-2006, 04:13 PM   · #4
Tree
NamePros Regular
 
Tree's Avatar
 
Name: Trevor
Location: Atlanta, GA, USA
Trader Rating: (3)
Join Date: Feb 2006
Posts: 334
NP$: 0.00 (Donate)
Tree will become famous soon enoughTree will become famous soon enough
http://www.php.net

Great resource for the PHP functions
__________________
NCIDev.com
Tree is offline   Reply With Quote
Old 04-07-2006, 04:44 PM   · #5
unknowngiver
Senior Member
 
Name: Zubair
Location: Ontario Canada
Trader Rating: (53)
Join Date: May 2005
Posts: 2,754
NP$: 724.15 (Donate)
unknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to all
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 !!
unknowngiver is offline   Reply With Quote
Old 04-07-2006, 04:53 PM   · #6
clowesy
Account Suspended
 
Trader Rating: (13)
Join Date: Aug 2005
Posts: 379
NP$: 385.00 (Donate)
clowesy is a jewel in the roughclowesy is a jewel in the roughclowesy is a jewel in the rough
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
{}


?>
clowesy is offline   Reply With Quote
Old 04-07-2006, 05:00 PM   · #7
unknowngiver
Senior Member
 
Name: Zubair
Location: Ontario Canada
Trader Rating: (53)
Join Date: May 2005
Posts: 2,754
NP$: 724.15 (Donate)
unknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to all
grr but y isnt the gettype not working? y isnt recognizing numbers as integers?
unknowngiver is offline   Reply With Quote
Old 04-07-2006, 05:07 PM   · #8
Tree
NamePros Regular
 
Tree's Avatar
 
Name: Trevor
Location: Atlanta, GA, USA
Trader Rating: (3)
Join Date: Feb 2006
Posts: 334
NP$: 0.00 (Donate)
Tree will become famous soon enoughTree will become famous soon enough
Why does it matter? You can use the is_whatever family of functions to do it more efficiently.
__________________
NCIDev.com
Tree is offline   Reply With Quote
Old 04-07-2006, 06:51 PM   · #9
unknowngiver
Senior Member
 
Name: Zubair
Location: Ontario Canada
Trader Rating: (53)
Join Date: May 2005
Posts: 2,754
NP$: 724.15 (Donate)
unknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to all
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
unknowngiver is offline   Reply With Quote
Old 04-07-2006, 07:16 PM   · #10
Jim_
NamePros Regular
 
Jim_'s Avatar
 
Name: Jim, of course
Location: Philadelphia
Trader Rating: (20)
Join Date: Aug 2005
Posts: 558
NP$: 14.30 (Donate)
Jim_ is a glorious beacon of lightJim_ is a glorious beacon of lightJim_ is a glorious beacon of lightJim_ is a glorious beacon of lightJim_ is a glorious beacon of light
Save The Children
I think it's not working because the post variable is handled as a string.
__________________
woop woop
Jim_ is offline   Reply With Quote
Old 04-07-2006, 07:26 PM   · #11
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 


Name: Eric
Location: Kentucky
Trader Rating: (142)
Join Date: Mar 2005
Posts: 4,268
NP$: 1152.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet
Originally Posted by Jim_
I think it's not working because the post variable is handled as a string.


and using is_int will produce the same result. Btw, to quote the PHP manual:
Quote:
Never use gettype() to test for a certain type, since the returned string may be subject to change in a future version. In addition, it is slow too, as it involves string comparison.

Instead, use the is_* functions.



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 ";
}

?>
__________________

SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.3 now available!!

Last edited by SecondVersion : 04-07-2006 at 07:31 PM.
SecondVersion is offline   Reply With Quote
Old 04-09-2006, 02:34 PM   · #12
unknowngiver
Senior Member
 
Name: Zubair
Location: Ontario Canada
Trader Rating: (53)
Join Date: May 2005
Posts: 2,754
NP$: 724.15 (Donate)
unknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to all
okay got it
Thanks
unknowngiver is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Site Sponsors
Buy Flash Arcade Game Script Hunting Moon RealTechNetwork
Advertise your business at NamePros
All times are GMT -7. The time now is 09:59 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0