473,320 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 1820
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
37
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
28
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
23
by: florian.loitsch | last post by:
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.