General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 4th, 2003, 04:59 PM
CHornJr's Avatar
CHornJr CHornJr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: New York City
Posts: 236 CHornJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 50 m 36 sec
Reputation Power: 7
Send a message via AIM to CHornJr Send a message via MSN to CHornJr Send a message via Yahoo to CHornJr
Exclamation FUnction not working

On my news page I pulled some repetative code out and made it into a seperate function. I made no change to the code other then that.
If the user is logged in it is supposed to show on news articles the option to edit or remove the article. However it is not doing that anymore.

The function that retrieves the users level seems not to be getting the level here, however it is working correctly when called by template2.php.

I can not figure out why it is not working. The problem is at line 84 in news.php

I would appreciate any and all help
Attached Files
File Type: zip chornjr_function_error.zip (4.9 KB, 171 views)
__________________
CHornJr
"One day I'll know what I am doing"
My Blog
Suanhacky Lodge #49
Rebel Squadrons

Reply With Quote
  #2  
Old November 5th, 2003, 08:33 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Instead of using globals, try returning values. For testing, at any rate, try saying doing $level=checklogin() and, in the function, returning the value you're currently putting in $level.

Does it set the name properly?

Reply With Quote
  #3  
Old November 5th, 2003, 05:41 PM
CHornJr's Avatar
CHornJr CHornJr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: New York City
Posts: 236 CHornJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 50 m 36 sec
Reputation Power: 7
Send a message via AIM to CHornJr Send a message via MSN to CHornJr Send a message via Yahoo to CHornJr
I did keep it as a global variable in addition to having it return $level. But I must now ask; Why did I have to set eh function to return $level?

Reply With Quote
  #4  
Old November 6th, 2003, 08:17 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
I just offered it as an option. You can usually use globals, though it's not the best idea. Ideally, you should strive to keep your variables scoped, preferably within objects, etc. With global variables, you risk having functions with overlapping names screw up other functionality, and if you're developing in an environment with multiple developers, it can be a nightmare. It's typically better to pass a function some inputs, work with them within the scope of the function, and return outputs for use within the parent scope. This keeps things tidy and makes it harder for namespace issues to cause pesky hard-to-trace bugs.

Actually, I just took another quick look at your code and I think I know why $level wasn't working. In your news.php, you don't identify $level as a global variable, so it doesn't adopt the value you assign it in your checklogin() function. I'll bet that if you declare $level global in news.php and remove the return functionality, it'll work. Still, it tends to be cleaner and less problematic and more maintenance-friendly to pass inputs to and return outputs from your functions.

Reply With Quote
  #5  
Old November 6th, 2003, 12:31 PM
CHornJr's Avatar
CHornJr CHornJr is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: New York City
Posts: 236 CHornJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 50 m 36 sec
Reputation Power: 7
Send a message via AIM to CHornJr Send a message via MSN to CHornJr Send a message via Yahoo to CHornJr
thank you

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > FUnction not working


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT