Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

help with if/then

Posted on 2007-03-25
5
Medium Priority
?
173 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 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

670 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