471,073 Members | 1,299 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

If statement

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

Jul 17 '05 #1
3 1756
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

Jul 17 '05 #2
"Gilles Girard" <gg*****@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" ) { ?>
Jul 17 '05 #3
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

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by Fábio Mendes | last post: by
13 posts views Thread by eman1000 | last post: by
37 posts views Thread by Steven Bethard | last post: by
18 posts views Thread by Steven Bethard | last post: by
28 posts views Thread by Steven Bethard | last post: by
7 posts views Thread by Steven Bethard | last post: by
18 posts views Thread by dspfun | last post: by
23 posts views Thread by florian.loitsch | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.