Current location: Hot Scripts Forums » Programming Languages » PHP » if variable empty help


if variable empty help

Reply
  #1 (permalink)  
Old 03-20-09, 08:31 PM
Textahead Textahead is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
if variable empty help

I have a variable in a link <a href= blah.php?city=LA> Los Angeles </a>
on next page the variable $state is set to = 'city'
this works fine until the varible "city" is empty
I need a way to NOT reset $state if city is empty


<?php if($city !== '' && $city !== 'N/A'){$state=$_GET['city'];} else {$state=$state;} ?>

with this once 'city' is empty it vives $state the value as $_GET[$city]
any ideas? there must be a way
Reply With Quote
  #2 (permalink)  
Old 03-20-09, 08:38 PM
landing's Avatar
landing landing is offline
Coding Addict
 
Join Date: Jul 2006
Location: Scotland
Posts: 302
Thanks: 0
Thanked 0 Times in 0 Posts
If 'city' is not set, what is the default value for $state then?

PHP Code:

if (empty($_GET['city']) || $_GET['city'] == 'N/A') {
     
// city unavailable in URL
     
$state = ??
} else {
     
// city available
     
$state $_GET['city'];

__________________
Always sanitise your data


Best regards
Reply With Quote
  #3 (permalink)  
Old 03-20-09, 09:03 PM
Textahead Textahead is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
loosing it

$state is set to nothing until the link is used then it is set to $state=$city
my problem is that on the next link clicked i loose both variables as they become empty
Reply With Quote
  #4 (permalink)  
Old 03-20-09, 10:13 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
It seems to me that you have the links duplicated on each page and each link goes to a different page.
So if you picked a link that has no value then $state and $city become empty.

Or maybe you have this setup on one page only and each link displays different content.
And when a link has no value then the values in $state and $city are lost.

But I could guess all night on how your program is set up.

Either way, to solve your problem, using sessions would work very well.
__________________
Jerry Broughton
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Assign empty string to a variable? Yoggi PHP 2 11-04-05 03:45 AM
using variable variables with multiple variables for parts of the name harlock PHP 7 07-26-05 07:35 PM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM
Help me guys Mister B. ASP 1 09-09-03 09:12 PM


All times are GMT -5. The time now is 08:31 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.