Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic coding error 1

Status
Not open for further replies.
Feb 16, 2003
87
GB
Hi! I'm passing some information through a browser to a .php page but this is causing me a nuisance.

The code below ALWAYS outputs "apple" no matter what $prefix is.

Why doesn't this work:

<?php

if ($prefix = "apple") {
echo "apple";
} elseif ($prefix = "banana") {
echo "banana";
}
?>

Many thanks

Simon
 
Hi,

A single = assigns a value to a variable and a double == checks the value.

So your script should read

Code:
<?php

if ($prefix == "apple") {
        echo "apple";
} elseif ($prefix == "banana") {
        echo "banana";
} 
?>

Kind Regards, Paul Benn

**** Never Giveup, keep trying, the answer is out there!!! ****
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top