Solved

help with if/then

Posted on 2007-03-25
5
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

636 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