1
bb2120
A question of PHP
  • 2006/1/23 20:08

  • bb2120

  • Not too shy to talk

  • Posts: 179

  • Since: 2005/7/6 1


The answer to my question may be complex, or blindingly obvious (probably the latter).

Here goes...

In PHP, is there a way of performing a function if multiple conditions are true, and if any are false, doing something else. Okay, of course there is - but how do I do it?

Incase you don't get what I mean:

I have three user input fields that I want to check are filled with only numbers (using a regular expression). I want to make it so that if any of these fields do not match the regular expression, my script will say "you entered a load of rubbish"



For example - this how it might be coded if I'd invented php!

If($_GET['a']==//a number) and ($_GET['b']==//a number) and ($_GET['c']==//a number) {
example_function();
} else {
print_mistake_message


Any help much appreciated

2
m0nty
Re: A question of PHP
  • 2006/1/23 20:17

  • m0nty

  • XOOPS is my life!

  • Posts: 3337

  • Since: 2003/10/24


use is_numeric()

3
m0nty
Re: A question of PHP
  • 2006/1/23 20:25

  • m0nty

  • XOOPS is my life!

  • Posts: 3337

  • Since: 2003/10/24


If(is_numeric(trim($_GET['a'])) && (trim($_GET['b'])) && (trim($_GET['c']))) {
example_function();
} else {
print_mistake_message
}

might not be correct as my coding is far from proficient.

4
kaotik
Re: A question of PHP
  • 2006/1/23 20:29

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


If (($_GET['a']==1) && ($_GET['b']==2) && ($_GET['c']==3)) {
example_function();
} else {
print_mistake_message
}
www.kaotik.biz

5
bb2120
Re: A question of PHP
  • 2006/1/23 20:36

  • bb2120

  • Not too shy to talk

  • Posts: 179

  • Since: 2005/7/6 1


&& - Fantastic!


Cheers guys!


Quote:
might not be correct as my coding is far from proficient.


M0nty - you're talking a load of rubbish - you're coding knowledge is spectacular!

6
m0nty
Re: A question of PHP
  • 2006/1/23 20:36

  • m0nty

  • XOOPS is my life!

  • Posts: 3337

  • Since: 2003/10/24


that would work kaotik :) i guess it depends exactly what he wants tho.. values 1 2 & 3 could be variables if it's from a form input..

7
kaotik
Re: A question of PHP
  • 2006/1/23 20:40

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


getting the "()" right is normally what gives me headaches ;)
www.kaotik.biz

8
m0nty
Re: A question of PHP
  • 2006/1/23 20:44

  • m0nty

  • XOOPS is my life!

  • Posts: 3337

  • Since: 2003/10/24


yeah i miss the () at times.. lol

i used trim tho if GET is a variable from a form, because if any whitespace is sent with the variable is_numeric will always return false.. so u need to trim it all so u just have the value..

Login

Who's Online

95 user(s) are online (55 user(s) are browsing Support Forums)


Members: 0


Guests: 95


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits