Solved

help with if/then

Posted on 2007-03-25
5
169 Views
Last Modified: 2013-12-13
strange result from IF/THEN check

in my index.php page i have a check to see if the $id has been passed through the URL
if not then i redirect the user.

When i visit:
http://www.mysite.com/members/?id=
or
http://www.mysite.com/members/index.php

the result of the following is always
if($id = ""){
 echo"i am blank";
} else {
 echo"i have data";
}

<html><body> "i have data" </body></html>

I've tried $_GET['id'] and $id and both return the same thing
that $id is set and has data

so what's worng with this simple fi/then?
I need to check if the URL contians $id=??? if it's empty or not passed o need to rediredt the user.


0
Comment
Question by:luckynh
  • 3
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
JamesCssl earned 50 total points
ID: 18789479
you have to use the double equals:

if($id == ""){
 echo"i am blank";
} else {
 echo"i have data";
}
0
 
LVL 11

Expert Comment

by:JamesCssl
ID: 18789481
In PHP, = is only an assignment operator; you have to use == to compare values, and === to compare values, and make sure they are the same type.
0
 
LVL 3

Author Comment

by:luckynh
ID: 18789489
yea i tred the == but that didnt work eigher
0
 
LVL 11

Expert Comment

by:JamesCssl
ID: 18789508
How are you assigning the value to $id?
You could try something like the following:

if(!(isset($_GET['id'])&&$_GET['id'] != '')){
 echo"i am blank";
} else {
 echo"i have data";
}
0
 
LVL 3

Author Comment

by:luckynh
ID: 18789542
well i changed the VAR to a different word and not it's working

if($memberid == ""){
 echo"i am blank";
} else {
 echo"i have data";
}

when i use $id it does not work but $memeberid does.. strange..

this is the 1st line of code in the page so $id is not being set any where... strange
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now