This is a discussion on If statement within the PHP Language forums, part of the PHP Programming Forums category; Hi, I use a sample code showed in php.net website manual with my conditions, and the result is always ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I use a sample code showed in php.net website manual with my conditions, and the result is always true. <?php if ( $username="myusername" AND $password="mypassword" ) { ?> True <?php } else { ?> False <?php } ?> Where's the bug? Thanks in advance Gilles Girard |
|
|||
|
Gilles Girard wrote:
> > I use a sample code showed in php.net website manual with my > conditions, and the result is always true. > > <?php if ( $username="myusername" AND $password="mypassword" ) { ?> > That's because '=' is an assignment and '==' is what you are looking for. JW |
|
|||
|
On 2004-08-11 17:22:08 -0400, "Janwillem Borleffs" <jw@jwscripts.com> said:
> Gilles Girard wrote: >> >> I use a sample code showed in php.net website manual with my >> conditions, and the result is always true. >> >> <?php if ( $username="myusername" AND $password="mypassword" ) { ?> >> > > That's because '=' is an assignment and '==' is what you are looking for. > > > JW It's work. Thank you very much GG |
|
|||
|
"Gilles Girard" <ggirard@blowupgalerie.com> wrote in message
news:2004081117093680432%ggirard@blowupgaleriecom. .. > Hi, > > I use a sample code showed in php.net website manual with my > conditions, and the result is always true. > > <?php if ( $username="myusername" AND $password="mypassword" ) { ?> > > True > > <?php } else { ?> > > False > > <?php } ?> > > Where's the bug? > > Thanks in advance > > Gilles Girard > The PHP equals (=) operator assigns variables. So, when your first line is this... <?php if ( $username="myusername" AND $password="mypassword" ) { ?> .... you are assigning $username the value "myusername" and $password the value "mypassword". In PHP, any string that does not equal "" or "0" is considered to be true. You must use the comparison operator (==) instead to compare the two variables to their respective strings. So your first line should be changed to this: <?php if ( $username=="myusername" AND $password=="mypassword" ) { ?> |