TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-14-2009, 12:23 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default $_GET error

Hi, I have a really weird error...

phpfile.php
PHP Code:

$year 
$_GET['year'];
        
        if(
is_numeric($year) || $year == 'current')
        {
        
            
$file 'subs/economy/' $year;
            
            if(
file_exists($temp->getFile($file))) 
            {
            
                
$temp->view($file);
                
            }
            
            else
            {
            
                
$data['msg'] = 'Sidan finns ej';
                
$temp->view('error'$data);
            
            }
            
        }
        
        elseif(!isset(
$year))
        {
        
            
$year 'current';
            
$temp->view('subs/economy/' $year);
        
        }
        
        else
        {
        
            
$data['msg'] = 'Sidan finns ej';
            
$temp->view('error'$data);
        
        } 
Viewing phpfile.php?year=2009 brings up the template subs/economy/2009.php. Viewing 2008.. well you get the point.

Problem is though, that if I'm just viewing phpfile.php it should set $year = 'current', but it gives me an undefined index error. Any ideas how I can set so if they give no parameter in the url, it should set the parameter to 'current'(it doesn't have to DISPLAY that in the url though)?
__________________
Tanax is offline  
Reply With Quote
Old 08-14-2009, 12:53 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

You need to check if the year was provided, if not use current as a default.
PHP Code:
$year = isset($_GET['year']) ? $_GET['year'] : 'current'
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
Tanax (08-14-2009)
Old 08-14-2009, 02:36 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Yea, I tried like this:
PHP Code:
if(isset($_GET['year'])) $year $_GET['year']; 
But that didn't work. Your code worked however. So thanks!
__________________
Tanax is offline  
Reply With Quote
Old 08-14-2009, 04:40 PM   #4 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Yea, I tried like this:
PHP Code:
if(isset($_GET['year'])) $year $_GET['year']; 
But that didn't work. Your code worked however. So thanks!
His worked because you were not setting a default value if none was found, so PHP was using a[n] ''. <-- {Blank Space}
__________________
My Site
adamdecaf is offline  
Reply With Quote
The Following User Says Thank You to adamdecaf For This Useful Post:
Tanax (08-14-2009)
Old 08-14-2009, 07:44 PM   #5 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Ooh.. right.. thanks
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Parse error: parse error,syntex error unexpected ',' expectingT_STRING in my code tech Absolute Beginners 13 01-29-2013 10:00 AM
cant work this error out talonos Absolute Beginners 11 07-13-2009 11:03 AM
Can't solve browser error Peuplarchie Absolute Beginners 1 06-09-2008 05:48 AM
Keep getting mySQL error No. 1064, but i can't seem to find the problem Durux MySQL & Databases 8 04-13-2008 07:51 PM
an error makes me crazy nuts !!!!!!! webtuto Absolute Beginners 1 02-27-2008 10:31 AM


All times are GMT. The time now is 10:54 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design