Re: Php ignores if statement
| From: | RT | Date: | Sat, 22 Nov 2003 19:48:21 +0000 |
| Subject: | Re: Php ignores if statement | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-170681@lists.php.net to get a copy of this message | ||
On Sat, 2003-11-22 at 13:57, Pieter wrote:
> I recently started coding online and i have the weirdest response, my code is:
>
> <?php
>
> include 'function.inc';
>
> echo "$id<br>";
>
> print (gettype($id));
>
> if ($id = "add" )
>
> {
>
> echo "is add";
>
> exit;
>
> }
>
>
> if ($id = "own" )
>
> {
>
>
> echo "id is own";
>
> exit;
>
> }
>
> if ($id = "all" )
>
> {
>
>
> echo "id is all";
>
> exit;
>
> }
>
> ?>
>
> $id in this case = "own", but it totally ignores this value and uses the first if
> statement and treats $id as if it has a value of "add". I am very frustrated and i really
> hope someone can help me. The server is linux, and php version 4.1.2
>
> Thanks
>
Don't use = use ==
By using the = you are assigning $id to that value making the if
statement always true.
The compare one to the other use == instead
--
"I have a photographic memory. I just forgot the film" --Unknown
=============================
Ryan Thompson
rthomp@sympatico.ca
http://osgw.sourceforge.net