Click to See Complete Forum and Search --> : PHP's starting to piss me off!


jacrewq
05-18-2003, 06:00 PM
This is part of my code:

if ($group == 0) $cfg->errmsg ("Please select a group.$group");

Notice that there should be an error message if $group is zero. And then in the error message the value of $group is displayed.

So the script outputs this: Please select a group.Ontario

That means that $group is Ontarion and ZERO in the SAME TIME!!!!

WHT??

Mordecai
05-18-2003, 06:29 PM
If you're checking if a string is a number, most of the time, it returns -1, it might just be zero in your case. Don't try to check a string against a number, unless you convert it some how.

epimeth
05-18-2003, 07:41 PM
try === instead of ==

planetsim
05-18-2003, 08:11 PM
What he had was suffient. He Doesnt need the === as that will make sure its identical which is not required.

$group should actually be the Goup names id instead of the Group itself.

jacrewq
05-18-2003, 09:36 PM
what do you mean by

$group should actually be the Goup names id instead of the Group itself.

Mordecai
05-18-2003, 11:55 PM
He means you shouldn't use the name for the ID. I.e. this example:
Person id #1 = Mordecai
Person id #2 = George Bush
Person id #3 = Pacman
if ((person id #3) == "Pacman") { }
this equals: if (3 == "Pacman"). Obviously, 3 does not equal Pacman. Therefore, you must use either:
if ("Pacman" == "Pacman")
or
if ((person id #3) == (person id #3))

Hope this helps, despite being a very confusing example that means almost nothing.

In simple terms: stick with either an ID or a name, don't mix and match, since they're obviously not the same when measuring equality.

Bunkermaster
05-19-2003, 08:09 PM
Originally posted by Mordecai
Hope this helps, despite being a very confusing example that means almost nothing.

O_o


w00t??

Sxooter
05-21-2003, 04:07 PM
Note that if you're check to see if a $var got set, then use isset:

if (!isset($group)) die("Group var ain't set pa!");

If it's set to nothing, then test for that:

if ($group=="") die("witty error message goes here");