Undefined Index error
Moderator: General Moderators
-
blindchild
- Forum Newbie
- Posts: 5
- Joined: Sat Aug 13, 2005 10:47 pm
- Location: London
Undefined Index error
Hi,
I am relatively new to php and decided to learn by doing and so I made myself a sort of blog.
95% of the site works fine, but one problem that I am having is an undefined index error that is generated on one of my pages. Its quite annoying and messes up the whole layout of the page. The error is as follows:
Notice: Undefined index: KT_id_blindblog in /usr/local/psa/home/vhosts/blindchild.com/httpdocs/blog/byArticle.php on line 117
Now I think I know why the error is appearing, its because no one has actually logged into the page and so there is no value for the KT_id_blindblog session variable. Ive rattled my brains to try and work out how to fix the problem, but I am getting no where. Getting rid of the error one way will simply generate an error somewhere else.
The page can be viewed here: http://www.blindchild.com/blog/byArticle.php?id_art=4.
Any advice, suggestions or links would really help me out. I'm at a dead end here.
Thank you
Ross[/url]
I am relatively new to php and decided to learn by doing and so I made myself a sort of blog.
95% of the site works fine, but one problem that I am having is an undefined index error that is generated on one of my pages. Its quite annoying and messes up the whole layout of the page. The error is as follows:
Notice: Undefined index: KT_id_blindblog in /usr/local/psa/home/vhosts/blindchild.com/httpdocs/blog/byArticle.php on line 117
Now I think I know why the error is appearing, its because no one has actually logged into the page and so there is no value for the KT_id_blindblog session variable. Ive rattled my brains to try and work out how to fix the problem, but I am getting no where. Getting rid of the error one way will simply generate an error somewhere else.
The page can be viewed here: http://www.blindchild.com/blog/byArticle.php?id_art=4.
Any advice, suggestions or links would really help me out. I'm at a dead end here.
Thank you
Ross[/url]
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
hint:
Code: Select all
isset($_SESSION['KT_id_blindblog'])-
blindchild
- Forum Newbie
- Posts: 5
- Joined: Sat Aug 13, 2005 10:47 pm
- Location: London
So close...yet so far
Thanks for the hint, I did try that before but it generated another error when it actually came to a user logging in and posting.
Ill give it another go, thanks for the hint, it seems I'm close.
Thanks
Ross
PS. Ill let you know if I sort it. Thanks again.
Ill give it another go, thanks for the hint, it seems I'm close.
Thanks
Ross
PS. Ill let you know if I sort it. Thanks again.
put it in an if/else
Code: Select all
if(isset($_SESSION['KT_id_blindblog']))
{
// the session variable is set, so do this
} ELSE
{
// the session variable is not set, so do this
}Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
... more along the lines of
Code: Select all
$_SESSION['KT_id_blindblog'] = (isset($_SESSION['KT_id_blindblog']) ? $_SESSION['KT_id_blindblog'] : 'default_value_goes_here');
//$_SESSION['KT_id_blindblog'] will always have been initialized by this point
echo $_SESSION['KT_id_blindblog'];
Last edited by John Cartwright on Sat Aug 13, 2005 11:44 pm, edited 1 time in total.
-
blindchild
- Forum Newbie
- Posts: 5
- Joined: Sat Aug 13, 2005 10:47 pm
- Location: London
Maybe....
Hi again,
I just gave it another go and it appears to have worked. But just to check, this is what I did.
I inserted the line:
before the default values are defined.
If I'm wrong let me know.
Thanks
Ross
**EDIT** Wow just saw some more poeple had posted. Ignore my attempt till Ive read yours, incase I have embarrassed myself. Thanks
I just gave it another go and it appears to have worked. But just to check, this is what I did.
I inserted the line:
Code: Select all
if (isset($_SESSION['KT_id_blindblog'])){If I'm wrong let me know.
Thanks
Ross
**EDIT** Wow just saw some more poeple had posted. Ignore my attempt till Ive read yours, incase I have embarrassed myself. Thanks
-
blindchild
- Forum Newbie
- Posts: 5
- Joined: Sat Aug 13, 2005 10:47 pm
- Location: London
Both solutions work
Hi,
Thanks for all your help, the page is functioning properly now.
Any ideas about which suggestion is the best? Because both seem to work fine...at the moment I am rolling with Jcart's suggestion, purely because he has more posts.
Thanks for the quick responses.
Ross
Thanks for all your help, the page is functioning properly now.
Any ideas about which suggestion is the best? Because both seem to work fine...at the moment I am rolling with Jcart's suggestion, purely because he has more posts.
Thanks for the quick responses.
Ross