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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP problem with $_GET

Status
Not open for further replies.

mcall

MIS
May 9, 2003
120
US
Am new to PHP and figure there's something I'm missing.

a$=$_GET["somedata"];
if ($a="cat") { do something }

The problem I'm having here, is regardless of what is passed, the if statement above always returns true and when I check the value of a$ after the if statement is called, I see that a=NULL.

What am I missing here?
 
2 things here.

The "$" symbol should always come before the variable name. So this:
Code:
a$=$_GET["somedata"];

Should be producing a syntax error.

Second, This:
Code:
if ($a="cat")

Is only checking if the assignment of the string "cat" to the variable a is successful. And since its always possible to assing a value to a variable, it s always true.

In PHP the comparison operator is a double equal sign.

So if you want to check if A has a value of "cat" it should look like this:

Code:
if ($a[red]==[/red]"cat")


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
thanks. a$ was a typo submitting the post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top