NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page wts wrong here

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 04-07-2006, 03:46 PM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes

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)){
????: NamePros.com http://www.namepros.com/programming/184870-wts-wrong-here.html
if (
$get != 'integer') {
echo 
"You posted $stuff and its not an integer";}
else
{echo 
"thanks " ;}
}
else 
{}


?>
unknowngiver is offline  
Old 04-07-2006, 03:50 PM   #2 (permalink)
Account Suspended
Join Date: Aug 2005
Posts: 379
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  
Old 04-07-2006, 04:06 PM THREAD STARTER               #3 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes
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  
Old 04-07-2006, 04:13 PM   #4 (permalink)
NamePros Regular
 
Tree's Avatar
Join Date: Feb 2006
Location: Atlanta, GA, USA
Posts: 335
Tree will become famous soon enoughTree will become famous soon enough
 



http://www.php.net

Great resource for the PHP functions
Tree is offline  
Old 04-07-2006, 04:44 PM THREAD STARTER               #5 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes
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  
Old 04-07-2006, 04:53 PM   #6 (permalink)
Account Suspended
Join Date: Aug 2005
Posts: 379
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  
Old 04-07-2006, 05:00 PM THREAD STARTER               #7 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes
grr but y isnt the gettype not working? y isnt recognizing numbers as integers?
unknowngiver is offline  
Old 04-07-2006, 05:07 PM   #8 (permalink)
NamePros Regular
 
Tree's Avatar
Join Date: Feb 2006
Location: Atlanta, GA, USA
Posts: 335
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.
Tree is offline  
Old 04-07-2006, 06:51 PM THREAD STARTER               #9 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes
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  
Old 04-07-2006, 07:16 PM   #10 (permalink)
NamePros Regular
 
Jim_'s Avatar
Join Date: Aug 2005
Location: NY, USA
Posts: 610
Jim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to behold
 


Save The Children
I think it's not working because the post variable is handled as a string.
__________________
ask me about the internet
Jim_ is offline  
Old 04-07-2006, 07:26 PM   #11 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

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 Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
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:
????: NamePros.com http://www.namepros.com/showthread.php?t=184870
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 ";
}

?>
Last edited by SecondVersion; 04-07-2006 at 07:31 PM.
Eric is offline  
Old 04-09-2006, 02:34 PM THREAD STARTER               #12 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes
okay got it
Thanks
unknowngiver is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 03:26 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger