Solved

help with if/then

Posted on 2007-03-25
5
171 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

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…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

734 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