Computing.Net > Forums > Web Development > Simple PHP Validation script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Simple PHP Validation script

Reply to Message Icon

Name: rhawkes241
Date: May 30, 2006 at 03:59:24 Pacific
OS: Windows xp
CPU/Ram: Athlon XP 1700, 512SD
Comment:

Hi,

I'm still new to PHP (I've just got over the excitment of how the include statement works, its excellent it really is).

Anyway, I need to create a PHP script. I have an input from a user (for arguments sake called $inputstring). Once the varible is in $inputstring, I need the script to decide whether its a numeric entry (e.g. 54) or whether its something else like text. If it's a number then I want it to stay in the varible $inputstring, and then it'll run some code I create, if its anything else like text or symbols I want $inputstring set to 1.

I know this is probably easy to do, however I am new to PHP. Also if any of you could recomend good (interesting) books for training or websites that would be handy.

Thanks in advance!



Sponsored Link
Ads by Google

Response Number 1
Name: Laler
Date: May 30, 2006 at 05:57:45 Pacific
Reply:

if (is_numeric ($inputstring))
{
echo $inputstring . ' is a number';
}
else
{
die ();
}

---
Site of the Day


0

Response Number 2
Name: Laler
Date: May 30, 2006 at 06:04:50 Pacific
Reply:

ah sorry didnt read to the end.

if (is_numeric ($inputstring))
{
// do stuffs
}
else
{
$inputstring = 1;
}

For PHP learning, do googlesearch on phpfreaks, php.net, phpbuilder, sitepoint, computing.net, etc., like this.


---
Site of the Day


0

Response Number 3
Name: rhawkes241
Date: May 30, 2006 at 06:46:05 Pacific
Reply:

thats fantastic - many thanks!


0

Response Number 4
Name: OnlyJC
Date: June 13, 2006 at 03:20:37 Pacific
Reply:

Shorthand version:

$inputstring = (is_numeric($inputstring)) ? "$inputstring" : "1";

Do whatever with $inputstring now

OnlyJC
www.purple-fire.com


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Simple PHP Validation script

php upload script?? www.computing.net/answers/webdevel/php-upload-script/2083.html

php forum script www.computing.net/answers/webdevel/php-forum-script/3790.html

Noob designer! Need help! www.computing.net/answers/webdevel/noob-designer-need-help/2398.html