Solved

help with if/then

Posted on 2007-03-25
5
170 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:Timothy Golden
  • 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:Timothy Golden
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:Timothy Golden
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 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